Skip to content

Commit e19454b

Browse files
author
ken miles
committed
Check errors on all the things
1 parent c064caa commit e19454b

File tree

8 files changed

+27
-22
lines changed

8 files changed

+27
-22
lines changed

CreateInvoice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (s *BillingService) CreateInvoice(userID int, invoice CreateInvoiceRequest)
8282
// WHMCS returns a error sometimes that is not in JSON !
8383
r := strings.Replace(resp.Body, `<div class="alert alert-error">Module credit_purchase_improvement: Module error occured. Please contact with support.</div>`, ``, -1)
8484
ir := InvoiceReply{}
85-
json.Unmarshal([]byte(r), &ir)
85+
err = json.Unmarshal([]byte(r), &ir)
8686

8787
return ir.InvoiceID, resp, err
8888

GetClients.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ func (s *AccountsService) GetClients(parms map[string]string) (*WHMCSclients, *R
2727
return nil, resp, err
2828
}
2929

30-
json.Unmarshal([]byte(resp.Body), &obj)
30+
err = json.Unmarshal([]byte(resp.Body), &obj)
3131
return obj, resp, err
3232
}

GetClientsDetails.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (s *AccountsService) GetClientsDetails(parms map[string]string) (*Account,
2828
return nil, resp, err
2929
}
3030

31-
json.Unmarshal([]byte(resp.Body), &a)
31+
err = json.Unmarshal([]byte(resp.Body), &a)
3232

3333
return a, resp, err
3434
}

GetClientsProducts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (s *AccountsService) GetClientsProducts(parms map[string]string) (*ClientsP
5656
return nil, resp, err
5757
}
5858

59-
json.Unmarshal([]byte(resp.Body), &p)
59+
err = json.Unmarshal([]byte(resp.Body), &p)
6060

6161
return p, resp, err
6262
}

UpdateClientProduct.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (s *SystemService) UpdateClientProduct(parms map[string]string) (*UpdateCli
9494
return nil, resp, err
9595
}
9696

97-
json.Unmarshal([]byte(resp.Body), &obj)
97+
err = json.Unmarshal([]byte(resp.Body), &obj)
9898
return obj, resp, err
9999
}
100100

UpdateInvoice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ func (s *BillingService) UpdateInvoice(invoiceID int, items []InvoiceLineItems)
7777
return nil, resp, err
7878
}
7979

80-
json.Unmarshal([]byte(resp.Body), &i)
80+
err = json.Unmarshal([]byte(resp.Body), &i)
8181
return i, resp, err
8282
}

accounts.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (s *AccountsService) GetContacts(parms map[string]string) (*Account, *Respo
211211
return nil, resp, err
212212
}
213213

214-
json.Unmarshal([]byte(resp.Body), &a)
214+
err = json.Unmarshal([]byte(resp.Body), &a)
215215

216216
return a, resp, err
217217
}
@@ -280,7 +280,10 @@ func (s *AccountsService) ClientContactList(status string) ([]ContactList, error
280280
if err != nil {
281281
fmt.Println(err)
282282
}
283-
json.Unmarshal([]byte(resp.Body), &cl)
283+
err = json.Unmarshal([]byte(resp.Body), &cl)
284+
if err != nil {
285+
fmt.Println(err)
286+
}
284287

285288
cl.VendorSoftware = strings.TrimSpace(cl.VendorSoftware)
286289
cl.Phone = strings.Replace(cl.Phone, "+61.", "0", -1)
@@ -335,17 +338,11 @@ func (s *AccountsService) ClientLastBilled(status string) ([]ClientLastBilledLis
335338
if err != nil {
336339
fmt.Println(err)
337340
}
338-
json.Unmarshal([]byte(resp.Body), &cl)
339-
// cl.Phone = strings.Replace(cl.Phone, "+61.", "0", -1)
340-
// cl.Phone = strings.Replace(cl.Phone, " ", "", -1)
341-
// if len(cl.Phone) == 10 {
342-
// cl.Phone = fmt.Sprintf("%s %s %s", cl.Phone[0:4], cl.Phone[4:7], cl.Phone[7:10])
343-
// }
344-
345-
// cl.AlertPrimary = strings.Replace(cl.AlertPrimary, " ", "", -1)
346-
// if len(cl.AlertPrimary) == 10 {
347-
// cl.AlertPrimary = fmt.Sprintf("%s %s %s", cl.AlertPrimary[0:4], cl.AlertPrimary[4:7], cl.AlertPrimary[7:10])
348-
// }
341+
err = json.Unmarshal([]byte(resp.Body), &cl)
342+
343+
if err != nil {
344+
fmt.Println(err)
345+
}
349346

350347
contactList = append(contactList, cl)
351348
}

billing.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ func (s *BillingService) GetLastInvoice(userid int, status string) (Invoice, err
115115
return Invoice{}, err
116116
}
117117

118-
json.Unmarshal([]byte(resp.Body), &invoices)
118+
err = json.Unmarshal([]byte(resp.Body), &invoices)
119+
120+
if err != nil {
121+
return Invoice{}, fmt.Errorf("Can't unmarshal invoices: %w", err)
122+
}
119123

120124
if invoices.Numreturned > 0 {
121125
return invoices.Invoices.Invoice[0], nil
@@ -160,7 +164,11 @@ func (s *BillingService) GetInvoices(parms map[string]string) ([]Invoice, *Respo
160164
return nil, resp, err
161165
}
162166

163-
json.Unmarshal([]byte(resp.Body), &invoices)
167+
err = json.Unmarshal([]byte(resp.Body), &invoices)
168+
169+
if err != nil {
170+
return nil, nil, fmt.Errorf("unable to unmarshal invoices: %w", err)
171+
}
164172

165173
var r []Invoice
166174
for _, i := range invoices.Invoices.Invoice {
@@ -207,6 +215,6 @@ func (s *BillingService) CapturePayment(invoice int) (*CaptureResult, *Response,
207215
return nil, resp, err
208216
}
209217

210-
json.Unmarshal([]byte(resp.Body), &result)
218+
err = json.Unmarshal([]byte(resp.Body), &result)
211219
return result, resp, err
212220
}

0 commit comments

Comments
 (0)