diff --git a/errs/error.go b/errs/error.go index 2730943..f6a6bfb 100644 --- a/errs/error.go +++ b/errs/error.go @@ -3,21 +3,67 @@ package errs import ( "encoding/json" "fmt" + "strconv" ) // Error returns the string representation of the error and satisfies the error interface. func (f *Failure) Error() string { - return f.RuntimeErr.Error() + if f != nil && f.runtimeErr != nil { + return f.runtimeErr.Error() + } + + return "" } // ApiError returns formatted string representation of the API error func (f *Failure) ApiError() string { - return fmt.Sprintf("%+v", f.ApiErr) + if f != nil && f.apiErr != "" { + return fmt.Sprintf("%+v", f.apiErr) + } + + return "" } // ApiErrors returns array of formatted strings that represents API errors -func (f *Failure) ApiErrors() interface{} { - return f.ApiErrs +func (f *Failure) ApiErrors() map[string]string { + if len(f.apiErrs) > 0 { + return f.apiErrs + } + + return nil +} + +// SetRuntimeError set runtime error value +func (f *Failure) SetRuntimeError(e error) { + f.runtimeErr = e +} + +// SetApiError set api error value +func (f *Failure) SetApiError(e string) { + f.apiErr = e +} + +// SetApiErrors set api errors value +func (f *Failure) SetApiErrors(e map[string]string) { + f.apiErrs = e +} + +// ErrorsHandler returns map +func ErrorsHandler(errs interface{}) map[string]string { + m := make(map[string]string) + + switch errs.(type) { + case map[string]interface{}: + for idx, val := range errs.(map[string]interface{}) { + m[idx] = val.(string) + } + case []interface{}: + for idx, val := range errs.([]interface{}) { + m[strconv.Itoa(idx)] = val.(string) + } + } + + return m } // ErrorResponse method diff --git a/errs/error_test.go b/errs/error_test.go index 1527c36..20d38d0 100644 --- a/errs/error_test.go +++ b/errs/error_test.go @@ -1,45 +1,50 @@ package errs import ( + "reflect" "testing" ) func TestFailure_ApiErrorsSlice(t *testing.T) { var err = Failure{} b := []byte(`{"success": false, "errorMsg": "Failed to activate module", "errors": ["Your account has insufficient funds to activate integration module"]}`) + expected := map[string]string{ + "0": "Your account has insufficient funds to activate integration module", + } resp, e := ErrorResponse(b) - err.RuntimeErr = e - err.ApiErr = resp.ErrorMsg + err.SetRuntimeError(e) + err.SetApiError(resp.ErrorMsg) if resp.Errors != nil { - err.ApiErrs = resp.Errors + err.SetApiErrors(ErrorsHandler(resp.Errors)) } - f, ok := resp.Errors.([]interface{}) + eq := reflect.DeepEqual(expected, err.ApiErrors()) - if !ok { - t.Errorf("%+v", f) + if eq != true { + t.Errorf("%+v", eq) } - } func TestFailure_ApiErrorsMap(t *testing.T) { var err = Failure{} b := []byte(`{"success": false, "errorMsg": "Failed to activate module", "errors": {"id": "ID must be an integer"}}`) + expected := map[string]string{ + "id": "ID must be an integer", + } resp, e := ErrorResponse(b) - err.RuntimeErr = e - err.ApiErr = resp.ErrorMsg + err.SetRuntimeError(e) + err.SetApiError(resp.ErrorMsg) if resp.Errors != nil { - err.ApiErrs = resp.Errors + err.SetApiErrors(ErrorsHandler(resp.Errors)) } - f, ok := resp.Errors.(map[string]interface{}) + eq := reflect.DeepEqual(expected, err.ApiErrors()) - if !ok { - t.Errorf("%+v", f) + if eq != true { + t.Errorf("%+v", eq) } - } diff --git a/errs/interfaces.go b/errs/interfaces.go index d8bedf1..371eec4 100644 --- a/errs/interfaces.go +++ b/errs/interfaces.go @@ -4,5 +4,5 @@ package errs type Error interface { error ApiError() string - ApiErrors() interface{} + ApiErrors() map[string]string } diff --git a/errs/types.go b/errs/types.go index a2705f2..5af2e43 100644 --- a/errs/types.go +++ b/errs/types.go @@ -2,9 +2,9 @@ package errs // Failure struct implode runtime & api errors type Failure struct { - RuntimeErr error - ApiErr string - ApiErrs interface{} + runtimeErr error + apiErr string + apiErrs map[string]string } // FailureResponse convert json error response into object diff --git a/v5/client.go b/v5/client.go index 532fe97..c3364fa 100644 --- a/v5/client.go +++ b/v5/client.go @@ -25,10 +25,10 @@ func New(url string, key string) *Client { } // GetRequest implements GET Request -func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte, int, errs.Failure) { +func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte, int, *errs.Failure) { var res []byte - var failure errs.Failure var prefix = "/api/v5" + failure := &errs.Failure{} if len(versioned) > 0 { s := versioned[0] @@ -40,7 +40,7 @@ func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte req, err := http.NewRequest("GET", fmt.Sprintf("%s%s%s", c.URL, prefix, urlWithParameters), nil) if err != nil { - failure.RuntimeErr = err + failure.SetRuntimeError(err) return res, 0, failure } @@ -52,18 +52,18 @@ func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte resp, err := c.httpClient.Do(req) if err != nil { - failure.RuntimeErr = err + failure.SetRuntimeError(err) return res, 0, failure } if resp.StatusCode >= http.StatusInternalServerError { - failure.ApiErr = fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode) + failure.SetApiError(fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode)) return res, resp.StatusCode, failure } res, err = buildRawResponse(resp) if err != nil { - failure.RuntimeErr = err + failure.SetRuntimeError(err) } if c.Debug { @@ -74,14 +74,14 @@ func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte } // PostRequest implements POST Request -func (c *Client) PostRequest(url string, postParams url.Values) ([]byte, int, errs.Failure) { +func (c *Client) PostRequest(url string, postParams url.Values) ([]byte, int, *errs.Failure) { var res []byte - var failure errs.Failure var prefix = "/api/v5" + failure := &errs.Failure{} req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s", c.URL, prefix, url), strings.NewReader(postParams.Encode())) if err != nil { - failure.RuntimeErr = err + failure.SetRuntimeError(err) return res, 0, failure } @@ -94,18 +94,18 @@ func (c *Client) PostRequest(url string, postParams url.Values) ([]byte, int, er resp, err := c.httpClient.Do(req) if err != nil { - failure.RuntimeErr = err + failure.SetRuntimeError(err) return res, 0, failure } if resp.StatusCode >= http.StatusInternalServerError { - failure.ApiErr = fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode) + failure.SetApiError(fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode)) return res, resp.StatusCode, failure } res, err = buildRawResponse(resp) if err != nil { - failure.RuntimeErr = err + failure.SetRuntimeError(err) return res, 0, failure } @@ -127,18 +127,14 @@ func buildRawResponse(resp *http.Response) ([]byte, error) { return res, nil } -func buildErr(data []byte) errs.Failure { - var err = errs.Failure{} - +func buildErr(data []byte, err *errs.Failure) { resp, e := errs.ErrorResponse(data) - err.RuntimeErr = e - err.ApiErr = resp.ErrorMsg + err.SetRuntimeError(e) + err.SetApiError(resp.ErrorMsg) if resp.Errors != nil { - err.ApiErrs = resp.Errors + err.SetApiErrors(errs.ErrorsHandler(resp.Errors)) } - - return err } // checkBy select identifier type @@ -173,7 +169,7 @@ func fillSite(p *url.Values, site []string) { // // data, status, err := client.APIVersions() // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -184,21 +180,22 @@ func fillSite(p *url.Values, site []string) { // for _, value := range data.versions { // fmt.Printf("%v\n", value) // } -func (c *Client) APIVersions() (VersionResponse, int, errs.Failure) { +func (c *Client) APIVersions() (VersionResponse, int, *errs.Failure) { var resp VersionResponse data, status, err := c.GetRequest("/api-versions", false) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // APICredentials get all available API methods for exact account @@ -211,7 +208,7 @@ func (c *Client) APIVersions() (VersionResponse, int, errs.Failure) { // // data, status, err := client.APICredentials() // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -222,21 +219,22 @@ func (c *Client) APIVersions() (VersionResponse, int, errs.Failure) { // for _, value := range data.credentials { // fmt.Printf("%v\n", value) // } -func (c *Client) APICredentials() (CredentialResponse, int, errs.Failure) { +func (c *Client) APICredentials() (CredentialResponse, int, *errs.Failure) { var resp CredentialResponse data, status, err := c.GetRequest("/credentials", false) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Customers returns list of customers matched the specified filter @@ -254,7 +252,7 @@ func (c *Client) APICredentials() (CredentialResponse, int, errs.Failure) { // Page: 3, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -265,23 +263,24 @@ func (c *Client) APICredentials() (CredentialResponse, int, errs.Failure) { // for _, value := range data.Customers { // fmt.Printf("%v\n", value) // } -func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, errs.Failure) { +func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, *errs.Failure) { var resp CustomersResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/customers?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CustomersCombine combine given customers @@ -294,14 +293,14 @@ func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, // // data, status, err := client.CustomersCombine([]v5.Customer{{ID: 1}, {ID: 2}}, Customer{ID: 3}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse combineJSONIn, _ := json.Marshal(&customers) @@ -313,17 +312,18 @@ func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) } data, status, err := c.PostRequest("/customers/combine", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CustomerCreate creates customer @@ -346,7 +346,7 @@ func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -357,7 +357,7 @@ func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) // if data.Success == true { // fmt.Printf("%v", err.Id) // } -func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChangeResponse, int, errs.Failure) { +func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChangeResponse, int, *errs.Failure) { var resp CustomerChangeResponse customerJSON, _ := json.Marshal(&customer) @@ -369,17 +369,18 @@ func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChan fillSite(&p, site) data, status, err := c.PostRequest("/customers/create", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CustomersFixExternalIds customers external ID @@ -395,14 +396,14 @@ func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChan // ExternalID: 12, // }}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse customersJSON, _ := json.Marshal(&customers) @@ -412,17 +413,18 @@ func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (Successfu } data, status, err := c.PostRequest("/customers/fix-external-ids", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CustomersHistory returns customer's history @@ -439,7 +441,7 @@ func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (Successfu // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -450,23 +452,24 @@ func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (Successfu // for _, value := range data.History { // fmt.Printf("%v\n", value) // } -func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (CustomersHistoryResponse, int, errs.Failure) { +func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (CustomersHistoryResponse, int, *errs.Failure) { var resp CustomersHistoryResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/customers/history?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CustomerNotes returns customer related notes @@ -484,7 +487,7 @@ func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (Customers // Page: 1, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -495,23 +498,24 @@ func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (Customers // for _, value := range data.Notes { // fmt.Printf("%v\n", value) // } -func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, errs.Failure) { +func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, *errs.Failure) { var resp NotesResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/customers/notes?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CustomerNoteCreate note creation @@ -530,7 +534,7 @@ func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, err // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -541,7 +545,7 @@ func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, err // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, int, errs.Failure) { +func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, int, *errs.Failure) { var resp CreateResponse noteJSON, _ := json.Marshal(¬e) @@ -553,17 +557,18 @@ func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, fillSite(&p, site) data, status, err := c.PostRequest("/customers/notes/create", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CustomerNoteDelete remove customer related note @@ -575,14 +580,14 @@ func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, // var client = v5.New("https://demo.url", "09jIJ") // // data, status, err := client.CustomerNoteDelete(12) -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse p := url.Values{ @@ -590,17 +595,18 @@ func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, errs.Failu } data, status, err := c.PostRequest(fmt.Sprintf("/customers/notes/%d/delete", id), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CustomersUpload customers batch upload @@ -628,7 +634,7 @@ func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, errs.Failu // }, // }} // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -639,7 +645,7 @@ func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, errs.Failu // if data.Success == true { // fmt.Printf("%v\n", data.UploadedCustomers) // } -func (c *Client) CustomersUpload(customers []Customer, site ...string) (CustomersUploadResponse, int, errs.Failure) { +func (c *Client) CustomersUpload(customers []Customer, site ...string) (CustomersUploadResponse, int, *errs.Failure) { var resp CustomersUploadResponse uploadJSON, _ := json.Marshal(&customers) @@ -651,17 +657,18 @@ func (c *Client) CustomersUpload(customers []Customer, site ...string) (Customer fillSite(&p, site) data, status, err := c.PostRequest("/customers/upload", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Customer returns information about customer @@ -674,7 +681,7 @@ func (c *Client) CustomersUpload(customers []Customer, site ...string) (Customer // // data, status, err := client.Customer(12, "externalId", "") // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -685,7 +692,7 @@ func (c *Client) CustomersUpload(customers []Customer, site ...string) (Customer // if data.Success == true { // fmt.Printf("%v\n", data.Customer) // } -func (c *Client) Customer(id, by, site string) (CustomerResponse, int, errs.Failure) { +func (c *Client) Customer(id, by, site string) (CustomerResponse, int, *errs.Failure) { var resp CustomerResponse var context = checkBy(by) @@ -693,17 +700,18 @@ func (c *Client) Customer(id, by, site string) (CustomerResponse, int, errs.Fail params, _ := query.Values(fw) data, status, err := c.GetRequest(fmt.Sprintf("/customers/%s?%s", id, params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CustomerEdit edit exact customer @@ -725,7 +733,7 @@ func (c *Client) Customer(id, by, site string) (CustomerResponse, int, errs.Fail // "id", // ) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -736,7 +744,7 @@ func (c *Client) Customer(id, by, site string) (CustomerResponse, int, errs.Fail // if data.Success == true { // fmt.Printf("%v\n", data.Customer) // } -func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (CustomerChangeResponse, int, errs.Failure) { +func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (CustomerChangeResponse, int, *errs.Failure) { var resp CustomerChangeResponse var uid = strconv.Itoa(customer.ID) var context = checkBy(by) @@ -755,17 +763,18 @@ func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (Cus fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/customers/%s/edit", uid), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // DeliveryTracking updates tracking data @@ -790,7 +799,7 @@ func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (Cus // "delivery-1", // ) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -798,7 +807,7 @@ func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (Cus // fmt.Printf("%v", err.ApiErr()) // } // -func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse updateJSON, _ := json.Marshal(¶meters) @@ -808,17 +817,18 @@ func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode st } data, status, err := c.PostRequest(fmt.Sprintf("/delivery/generic/%s/tracking", subcode), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // DeliveryShipments returns list of shipments @@ -836,7 +846,7 @@ func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode st // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -847,23 +857,24 @@ func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode st // for _, value := range data.DeliveryShipments { // fmt.Printf("%v\n", value) // } -func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (DeliveryShipmentsResponse, int, errs.Failure) { +func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (DeliveryShipmentsResponse, int, *errs.Failure) { var resp DeliveryShipmentsResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/delivery/shipments?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // DeliveryShipmentCreate creates shipment @@ -886,7 +897,7 @@ func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (Deliver // "sdek", // ) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -897,7 +908,7 @@ func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (Deliver // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType string, site ...string) (DeliveryShipmentUpdateResponse, int, errs.Failure) { +func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType string, site ...string) (DeliveryShipmentUpdateResponse, int, *errs.Failure) { var resp DeliveryShipmentUpdateResponse updateJSON, _ := json.Marshal(&shipment) @@ -909,17 +920,18 @@ func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType fillSite(&p, site) data, status, err := c.PostRequest("/delivery/shipments/create", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // DeliveryShipment get information about shipment @@ -932,7 +944,7 @@ func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType // // data, status, err := client.DeliveryShipment(12) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -943,21 +955,22 @@ func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType // if data.Success == true { // fmt.Printf("%v\n", data.DeliveryShipment) // } -func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, errs.Failure) { +func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, *errs.Failure) { var resp DeliveryShipmentResponse data, status, err := c.GetRequest(fmt.Sprintf("/delivery/shipments/%d", id)) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // DeliveryShipmentEdit shipment editing @@ -976,14 +989,14 @@ func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, errs.F // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) (DeliveryShipmentUpdateResponse, int, errs.Failure) { +func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) (DeliveryShipmentUpdateResponse, int, *errs.Failure) { var resp DeliveryShipmentUpdateResponse updateJSON, _ := json.Marshal(&shipment) @@ -994,17 +1007,18 @@ func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/delivery/shipments/%s/edit", strconv.Itoa(shipment.ID)), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // IntegrationModule returns integration module @@ -1017,7 +1031,7 @@ func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) // // data, status, err := client.IntegrationModule("moysklad3") // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1028,21 +1042,22 @@ func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) // if data.Success == true { // fmt.Printf("%v\n", data.IntegrationModule) // } -func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, errs.Failure) { +func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, *errs.Failure) { var resp IntegrationModuleResponse data, status, err := c.GetRequest(fmt.Sprintf("/integration-modules/%s", code)) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // IntegrationModuleEdit integration module create/edit @@ -1067,7 +1082,7 @@ func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, // Logo: "https://cdn.worldvectorlogo.com/logos/github-icon.svg", // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1078,24 +1093,25 @@ func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, // if data.Success == true { // fmt.Printf("%v\n", data.Info) // } -func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (IntegrationModuleEditResponse, int, errs.Failure) { +func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (IntegrationModuleEditResponse, int, *errs.Failure) { var resp IntegrationModuleEditResponse updateJSON, _ := json.Marshal(&integrationModule) p := url.Values{"integrationModule": {string(updateJSON[:])}} data, status, err := c.PostRequest(fmt.Sprintf("/integration-modules/%s/edit", integrationModule.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Orders returns list of orders matched the specified filters @@ -1108,7 +1124,7 @@ func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (Int // // data, status, err := client.Orders(v5.OrdersRequest{Filter: v5.OrdersFilter{City: "Moscow"}, Page: 1}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1119,23 +1135,24 @@ func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (Int // for _, value := range data.Orders { // fmt.Printf("%v\n", value) // } -func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, errs.Failure) { +func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, *errs.Failure) { var resp OrdersResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/orders?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrdersCombine combines given orders @@ -1148,14 +1165,14 @@ func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, errs.Fai // // data, status, err := client.OrdersCombine("ours", v5.Order{ID: 1}, v5.Order{ID: 1}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (OperationResponse, int, errs.Failure) { +func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (OperationResponse, int, *errs.Failure) { var resp OperationResponse combineJSONIn, _ := json.Marshal(&order) @@ -1168,17 +1185,18 @@ func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (Oper } data, status, err := c.PostRequest("/orders/combine", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrderCreate creates an order @@ -1197,7 +1215,7 @@ func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (Oper // Items: []v5.OrderItem{{Offer: v5.Offer{ID: 12}, Quantity: 5}}, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1208,7 +1226,7 @@ func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (Oper // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, errs.Failure) { +func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, *errs.Failure) { var resp CreateResponse orderJSON, _ := json.Marshal(&order) @@ -1219,17 +1237,18 @@ func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, fillSite(&p, site) data, status, err := c.PostRequest("/orders/create", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrdersFixExternalIds set order external ID @@ -1245,7 +1264,7 @@ func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, // ExternalID: 12, // }}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1256,7 +1275,7 @@ func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse ordersJSON, _ := json.Marshal(&orders) @@ -1266,17 +1285,18 @@ func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulRespo } data, status, err := c.PostRequest("/orders/fix-external-ids", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrdersHistory returns orders history @@ -1289,7 +1309,7 @@ func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulRespo // // data, status, err := client.OrdersHistory(v5.OrdersHistoryRequest{Filter: v5.OrdersHistoryFilter{SinceID: 20}}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1300,23 +1320,24 @@ func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulRespo // for _, value := range data.History { // fmt.Printf("%v\n", value) // } -func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistoryResponse, int, errs.Failure) { +func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistoryResponse, int, *errs.Failure) { var resp CustomersHistoryResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/orders/history?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrderPaymentCreate creates payment @@ -1335,7 +1356,7 @@ func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistor // Type: "cash", // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1346,7 +1367,7 @@ func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistor // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResponse, int, errs.Failure) { +func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResponse, int, *errs.Failure) { var resp CreateResponse paymentJSON, _ := json.Marshal(&payment) @@ -1358,17 +1379,18 @@ func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResp fillSite(&p, site) data, status, err := c.PostRequest("/orders/payments/create", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrderPaymentDelete payment removing @@ -1381,14 +1403,14 @@ func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResp // // data, status, err := client.OrderPaymentDelete(12) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse p := url.Values{ @@ -1396,17 +1418,18 @@ func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, errs.Failu } data, status, err := c.PostRequest(fmt.Sprintf("/orders/payments/%d/delete", id), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrderPaymentEdit edit payment @@ -1425,14 +1448,14 @@ func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, errs.Failu // "id", // ) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse var uid = strconv.Itoa(payment.ID) var context = checkBy(by) @@ -1450,17 +1473,18 @@ func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (S fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/orders/payments/%s/edit", uid), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrdersUpload batch orders uploading @@ -1488,7 +1512,7 @@ func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (S // } // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1499,7 +1523,7 @@ func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (S // if data.Success == true { // fmt.Printf("%v\n", data.UploadedOrders) // } -func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadResponse, int, errs.Failure) { +func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadResponse, int, *errs.Failure) { var resp OrdersUploadResponse uploadJSON, _ := json.Marshal(&orders) @@ -1511,17 +1535,18 @@ func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadRespo fillSite(&p, site) data, status, err := c.PostRequest("/orders/upload", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Order returns information about order @@ -1534,7 +1559,7 @@ func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadRespo // // data, status, err := client.Order(12, "externalId", "") // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1545,7 +1570,7 @@ func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadRespo // if data.Success == true { // fmt.Printf("%v\n", data.Order) // } -func (c *Client) Order(id, by, site string) (OrderResponse, int, errs.Failure) { +func (c *Client) Order(id, by, site string) (OrderResponse, int, *errs.Failure) { var resp OrderResponse var context = checkBy(by) @@ -1553,17 +1578,18 @@ func (c *Client) Order(id, by, site string) (OrderResponse, int, errs.Failure) { params, _ := query.Values(fw) data, status, err := c.GetRequest(fmt.Sprintf("/orders/%s?%s", id, params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrderEdit edit an order @@ -1582,14 +1608,14 @@ func (c *Client) Order(id, by, site string) (OrderResponse, int, errs.Failure) { // "id", // ) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateResponse, int, errs.Failure) { +func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateResponse, int, *errs.Failure) { var resp CreateResponse var uid = strconv.Itoa(order.ID) var context = checkBy(by) @@ -1608,17 +1634,18 @@ func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateRespon fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/orders/%s/edit", uid), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Packs returns list of packs matched the specified filters @@ -1631,7 +1658,7 @@ func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateRespon // // data, status, err := client.Packs(v5.PacksRequest{Filter: v5.PacksFilter{OrderID: 12}}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1642,23 +1669,24 @@ func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateRespon // for _, value := range data.Packs { // fmt.Printf("%v\n", value) // } -func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, errs.Failure) { +func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, *errs.Failure) { var resp PacksResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/orders/packs?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // PackCreate creates a pack @@ -1675,7 +1703,7 @@ func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, errs.Failur // Quantity: 1, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1686,7 +1714,7 @@ func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, errs.Failur // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) PackCreate(pack Pack) (CreateResponse, int, errs.Failure) { +func (c *Client) PackCreate(pack Pack) (CreateResponse, int, *errs.Failure) { var resp CreateResponse packJSON, _ := json.Marshal(&pack) @@ -1695,17 +1723,18 @@ func (c *Client) PackCreate(pack Pack) (CreateResponse, int, errs.Failure) { } data, status, err := c.PostRequest("/orders/packs/create", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // PacksHistory returns a history of order packing @@ -1718,7 +1747,7 @@ func (c *Client) PackCreate(pack Pack) (CreateResponse, int, errs.Failure) { // // data, status, err := client.PacksHistory(v5.PacksHistoryRequest{Filter: v5.OrdersHistoryFilter{SinceID: 5}}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1729,23 +1758,24 @@ func (c *Client) PackCreate(pack Pack) (CreateResponse, int, errs.Failure) { // for _, value := range data.History { // fmt.Printf("%v\n", value) // } -func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryResponse, int, errs.Failure) { +func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryResponse, int, *errs.Failure) { var resp PacksHistoryResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/orders/packs/history?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Pack returns a pack info @@ -1758,7 +1788,7 @@ func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryRespo // // data, status, err := client.Pack(112) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -1769,21 +1799,22 @@ func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryRespo // if data.Success == true { // fmt.Printf("%v\n", data.Pack) // } -func (c *Client) Pack(id int) (PackResponse, int, errs.Failure) { +func (c *Client) Pack(id int) (PackResponse, int, *errs.Failure) { var resp PackResponse data, status, err := c.GetRequest(fmt.Sprintf("/orders/packs/%d", id)) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // PackDelete removes a pack @@ -1796,28 +1827,29 @@ func (c *Client) Pack(id int) (PackResponse, int, errs.Failure) { // // data, status, err := client.PackDelete(112) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) PackDelete(id int) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) PackDelete(id int) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse data, status, err := c.PostRequest(fmt.Sprintf("/orders/packs/%d/delete", id), url.Values{}) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // PackEdit edit a pack @@ -1830,14 +1862,14 @@ func (c *Client) PackDelete(id int) (SuccessfulResponse, int, errs.Failure) { // // data, status, err := client.PackEdit(Pack{ID: 12, Quantity: 2}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) PackEdit(pack Pack) (CreateResponse, int, errs.Failure) { +func (c *Client) PackEdit(pack Pack) (CreateResponse, int, *errs.Failure) { var resp CreateResponse packJSON, _ := json.Marshal(&pack) @@ -1847,57 +1879,60 @@ func (c *Client) PackEdit(pack Pack) (CreateResponse, int, errs.Failure) { } data, status, err := c.PostRequest(fmt.Sprintf("/orders/packs/%d/edit", pack.ID), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Countries returns list of available country codes // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-countries -func (c *Client) Countries() (CountriesResponse, int, errs.Failure) { +func (c *Client) Countries() (CountriesResponse, int, *errs.Failure) { var resp CountriesResponse data, status, err := c.GetRequest("/reference/countries") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CostGroups returns costs groups list // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-cost-groups -func (c *Client) CostGroups() (CostGroupsResponse, int, errs.Failure) { +func (c *Client) CostGroups() (CostGroupsResponse, int, *errs.Failure) { var resp CostGroupsResponse data, status, err := c.GetRequest("/reference/cost-groups") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CostGroupEdit edit costs groups @@ -1913,14 +1948,14 @@ func (c *Client) CostGroups() (CostGroupsResponse, int, errs.Failure) { // Color: "#da5c98", // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&costGroup) @@ -1930,37 +1965,39 @@ func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, er } data, status, err := c.PostRequest(fmt.Sprintf("/reference/cost-groups/%s/edit", costGroup.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CostItems returns costs items list // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-cost-items -func (c *Client) CostItems() (CostItemsResponse, int, errs.Failure) { +func (c *Client) CostItems() (CostItemsResponse, int, *errs.Failure) { var resp CostItemsResponse data, status, err := c.GetRequest("/reference/cost-items") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CostItemEdit edit costs items @@ -1976,14 +2013,14 @@ func (c *Client) CostItems() (CostItemsResponse, int, errs.Failure) { // Active: false, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&costItem) @@ -1993,37 +2030,39 @@ func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, errs. } data, status, err := c.PostRequest(fmt.Sprintf("/reference/cost-items/%s/edit", costItem.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Couriers returns list of couriers // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-couriers -func (c *Client) Couriers() (CouriersResponse, int, errs.Failure) { +func (c *Client) Couriers() (CouriersResponse, int, *errs.Failure) { var resp CouriersResponse data, status, err := c.GetRequest("/reference/couriers") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CourierCreate creates a courier @@ -2041,7 +2080,7 @@ func (c *Client) Couriers() (CouriersResponse, int, errs.Failure) { // LastName: "Ivanov", // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -2052,7 +2091,7 @@ func (c *Client) Couriers() (CouriersResponse, int, errs.Failure) { // if data.Success == true { // fmt.Printf("%v", data.ID) // } -func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, errs.Failure) { +func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, *errs.Failure) { var resp CreateResponse objJSON, _ := json.Marshal(&courier) @@ -2062,17 +2101,18 @@ func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, errs.Failu } data, status, err := c.PostRequest("/reference/couriers/create", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // CourierEdit edit a courier @@ -2088,14 +2128,14 @@ func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, errs.Failu // Patronymic: "Ivanovich", // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&courier) @@ -2105,37 +2145,39 @@ func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, errs.Fai } data, status, err := c.PostRequest(fmt.Sprintf("/reference/couriers/%d/edit", courier.ID), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // DeliveryServices returns list of delivery services // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-delivery-services -func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, errs.Failure) { +func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, *errs.Failure) { var resp DeliveryServiceResponse data, status, err := c.GetRequest("/reference/delivery-services") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // DeliveryServiceEdit delivery service create/edit @@ -2151,14 +2193,14 @@ func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, errs.Failure) // Code: "delivery-1", // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&deliveryService) @@ -2168,37 +2210,39 @@ func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (Successfu } data, status, err := c.PostRequest(fmt.Sprintf("/reference/delivery-services/%s/edit", deliveryService.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // DeliveryTypes returns list of delivery types // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-delivery-types -func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, errs.Failure) { +func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, *errs.Failure) { var resp DeliveryTypesResponse data, status, err := c.GetRequest("/reference/delivery-types") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // DeliveryTypeEdit delivery type create/edit @@ -2216,14 +2260,14 @@ func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, errs.Failure) { // DefaultForCrm: false, // } // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&deliveryType) @@ -2233,37 +2277,39 @@ func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse } data, status, err := c.PostRequest(fmt.Sprintf("/reference/delivery-types/%s/edit", deliveryType.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // LegalEntities returns list of legal entities // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-legal-entities -func (c *Client) LegalEntities() (LegalEntitiesResponse, int, errs.Failure) { +func (c *Client) LegalEntities() (LegalEntitiesResponse, int, *errs.Failure) { var resp LegalEntitiesResponse data, status, err := c.GetRequest("/reference/legal-entities") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // LegalEntityEdit change information about legal entity @@ -2279,14 +2325,14 @@ func (c *Client) LegalEntities() (LegalEntitiesResponse, int, errs.Failure) { // CertificateDate: "2012-12-12", // } // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&legalEntity) @@ -2296,37 +2342,39 @@ func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, i } data, status, err := c.PostRequest(fmt.Sprintf("/reference/legal-entities/%s/edit", legalEntity.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrderMethods returns list of order methods // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-order-methods -func (c *Client) OrderMethods() (OrderMethodsResponse, int, errs.Failure) { +func (c *Client) OrderMethods() (OrderMethodsResponse, int, *errs.Failure) { var resp OrderMethodsResponse data, status, err := c.GetRequest("/reference/order-methods") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrderMethodEdit order method create/edit @@ -2343,14 +2391,14 @@ func (c *Client) OrderMethods() (OrderMethodsResponse, int, errs.Failure) { // DefaultForCRM: false, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&orderMethod) @@ -2360,37 +2408,39 @@ func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, i } data, status, err := c.PostRequest(fmt.Sprintf("/reference/order-methods/%s/edit", orderMethod.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrderTypes return list of order types // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-order-types -func (c *Client) OrderTypes() (OrderTypesResponse, int, errs.Failure) { +func (c *Client) OrderTypes() (OrderTypesResponse, int, *errs.Failure) { var resp OrderTypesResponse data, status, err := c.GetRequest("/reference/order-types") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // OrderTypeEdit create/edit order type @@ -2407,14 +2457,14 @@ func (c *Client) OrderTypes() (OrderTypesResponse, int, errs.Failure) { // DefaultForCRM: false, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&orderType) @@ -2424,43 +2474,45 @@ func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, er } data, status, err := c.PostRequest(fmt.Sprintf("/reference/order-types/%s/edit", orderType.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // PaymentStatuses returns list of payment statuses // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-payment-statuses -func (c *Client) PaymentStatuses() (PaymentStatusesResponse, int, errs.Failure) { +func (c *Client) PaymentStatuses() (PaymentStatusesResponse, int, *errs.Failure) { var resp PaymentStatusesResponse data, status, err := c.GetRequest("/reference/payment-statuses") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // PaymentStatusEdit payment status creation/editing // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-payment-statuses-code-edit -func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&paymentStatus) @@ -2470,43 +2522,45 @@ func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulRespo } data, status, err := c.PostRequest(fmt.Sprintf("/reference/payment-statuses/%s/edit", paymentStatus.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // PaymentTypes returns list of payment types // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-payment-types -func (c *Client) PaymentTypes() (PaymentTypesResponse, int, errs.Failure) { +func (c *Client) PaymentTypes() (PaymentTypesResponse, int, *errs.Failure) { var resp PaymentTypesResponse data, status, err := c.GetRequest("/reference/payment-types") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // PaymentTypeEdit payment type create/edit // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-payment-types-code-edit -func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&paymentType) @@ -2516,43 +2570,45 @@ func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, i } data, status, err := c.PostRequest(fmt.Sprintf("/reference/payment-types/%s/edit", paymentType.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // PriceTypes returns list of price types // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-price-types -func (c *Client) PriceTypes() (PriceTypesResponse, int, errs.Failure) { +func (c *Client) PriceTypes() (PriceTypesResponse, int, *errs.Failure) { var resp PriceTypesResponse data, status, err := c.GetRequest("/reference/price-types") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // PriceTypeEdit price type create/edit // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-price-types-code-edit -func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&priceType) @@ -2562,43 +2618,45 @@ func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, er } data, status, err := c.PostRequest(fmt.Sprintf("/reference/price-types/%s/edit", priceType.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // ProductStatuses returns list of item statuses in order // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-product-statuses -func (c *Client) ProductStatuses() (ProductStatusesResponse, int, errs.Failure) { +func (c *Client) ProductStatuses() (ProductStatusesResponse, int, *errs.Failure) { var resp ProductStatusesResponse data, status, err := c.GetRequest("/reference/product-statuses") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // ProductStatusEdit order item status create/edit // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-product-statuses-code-edit -func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&productStatus) @@ -2608,43 +2666,45 @@ func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulRespo } data, status, err := c.PostRequest(fmt.Sprintf("/reference/product-statuses/%s/edit", productStatus.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Sites returns the sites list // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-sites -func (c *Client) Sites() (SitesResponse, int, errs.Failure) { +func (c *Client) Sites() (SitesResponse, int, *errs.Failure) { var resp SitesResponse data, status, err := c.GetRequest("/reference/sites") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // SiteEdit site create/edit // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-sites-code-edit -func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&site) @@ -2654,63 +2714,66 @@ func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, errs.Failure) { } data, status, err := c.PostRequest(fmt.Sprintf("/reference/sites/%s/edit", site.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // StatusGroups returns list of order status groups // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-status-groups -func (c *Client) StatusGroups() (StatusGroupsResponse, int, errs.Failure) { +func (c *Client) StatusGroups() (StatusGroupsResponse, int, *errs.Failure) { var resp StatusGroupsResponse data, status, err := c.GetRequest("/reference/status-groups") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Statuses returns list of order statuses // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-statuses -func (c *Client) Statuses() (StatusesResponse, int, errs.Failure) { +func (c *Client) Statuses() (StatusesResponse, int, *errs.Failure) { var resp StatusesResponse data, status, err := c.GetRequest("/reference/statuses") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // StatusEdit order status create/edit // // For more information see www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-sites-code-edit -func (c *Client) StatusEdit(st Status) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) StatusEdit(st Status) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&st) @@ -2720,43 +2783,45 @@ func (c *Client) StatusEdit(st Status) (SuccessfulResponse, int, errs.Failure) { } data, status, err := c.PostRequest(fmt.Sprintf("/reference/statuses/%s/edit", st.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Stores returns list of warehouses // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-stores -func (c *Client) Stores() (StoresResponse, int, errs.Failure) { +func (c *Client) Stores() (StoresResponse, int, *errs.Failure) { var resp StoresResponse data, status, err := c.GetRequest("/reference/stores") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // StoreEdit warehouse create/edit // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-stores-code-edit -func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&store) @@ -2766,43 +2831,45 @@ func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, errs.Failure) } data, status, err := c.PostRequest(fmt.Sprintf("/reference/stores/%s/edit", store.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Units returns units list // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-units -func (c *Client) Units() (UnitsResponse, int, errs.Failure) { +func (c *Client) Units() (UnitsResponse, int, *errs.Failure) { var resp UnitsResponse data, status, err := c.GetRequest("/reference/units") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // UnitEdit unit create/edit // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-units-code-edit -func (c *Client) UnitEdit(unit Unit) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) UnitEdit(unit Unit) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse objJSON, _ := json.Marshal(&unit) @@ -2812,17 +2879,18 @@ func (c *Client) UnitEdit(unit Unit) (SuccessfulResponse, int, errs.Failure) { } data, status, err := c.PostRequest(fmt.Sprintf("/reference/units/%s/edit", unit.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Segments returns segments @@ -2839,7 +2907,7 @@ func (c *Client) UnitEdit(unit Unit) (SuccessfulResponse, int, errs.Failure) { // } // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -2850,23 +2918,24 @@ func (c *Client) UnitEdit(unit Unit) (SuccessfulResponse, int, errs.Failure) { // for _, value := range data.Segments { // fmt.Printf("%v\n", value) // } -func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, errs.Failure) { +func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, *errs.Failure) { var resp SegmentsResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/segments?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Inventories returns leftover stocks and purchasing prices @@ -2879,7 +2948,7 @@ func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, er // // data, status, err := client.Inventories(v5.InventoriesRequest{Filter: v5.InventoriesFilter{Details: 1, ProductActive: 1}, Page: 1}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -2890,23 +2959,24 @@ func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, er // for _, value := range data.Offers { // fmt.Printf("%v\n", value) // } -func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse, int, errs.Failure) { +func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse, int, *errs.Failure) { var resp InventoriesResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/store/inventories?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // InventoriesUpload updates the leftover stocks and purchasing prices @@ -2938,7 +3008,7 @@ func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse // }, // ) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -2947,7 +3017,7 @@ func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse // } // // fmt.Printf("%v\n", data.NotFoundOffers) -func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string) (StoreUploadResponse, int, errs.Failure) { +func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string) (StoreUploadResponse, int, *errs.Failure) { var resp StoreUploadResponse uploadJSON, _ := json.Marshal(&inventories) @@ -2959,17 +3029,18 @@ func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string fillSite(&p, site) data, status, err := c.PostRequest("/store/inventories/upload", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // PricesUpload updates prices @@ -2993,7 +3064,7 @@ func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3002,7 +3073,7 @@ func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string // } // // fmt.Printf("%v\n", data.NotFoundOffers) -func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, int, errs.Failure) { +func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, int, *errs.Failure) { var resp StoreUploadResponse uploadJSON, _ := json.Marshal(&prices) @@ -3012,17 +3083,18 @@ func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, i } data, status, err := c.PostRequest("/store/prices/upload", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // ProductsGroup returns list of product groups @@ -3039,7 +3111,7 @@ func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, i // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3050,23 +3122,24 @@ func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, i // for _, value := range data.ProductGroup { // fmt.Printf("%v\n", value) // } -func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroupsResponse, int, errs.Failure) { +func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroupsResponse, int, *errs.Failure) { var resp ProductsGroupsResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/store/product-groups?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Products returns list of products and SKU @@ -3084,7 +3157,7 @@ func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroups // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3095,23 +3168,24 @@ func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroups // for _, value := range data.Products { // fmt.Printf("%v\n", value) // } -func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, errs.Failure) { +func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, *errs.Failure) { var resp ProductsResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/store/products?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // ProductsProperties returns list of item properties, matching the specified filters @@ -3128,7 +3202,7 @@ func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, er // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3139,23 +3213,24 @@ func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, er // for _, value := range data.Properties { // fmt.Printf("%v\n", value) // } -func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (ProductsPropertiesResponse, int, errs.Failure) { +func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (ProductsPropertiesResponse, int, *errs.Failure) { var resp ProductsPropertiesResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/store/products/properties?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Tasks returns task list @@ -3172,7 +3247,7 @@ func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (Produ // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3183,23 +3258,24 @@ func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (Produ // for _, value := range data.Tasks { // fmt.Printf("%v\n", value) // } -func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, errs.Failure) { +func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, *errs.Failure) { var resp TasksResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/tasks?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // TaskCreate create a task @@ -3215,7 +3291,7 @@ func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, errs.Failur // PerformerID: 12, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3226,7 +3302,7 @@ func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, errs.Failur // if data.Success == true { // fmt.Printf("%v\n", data.ID) // } -func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, errs.Failure) { +func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, *errs.Failure) { var resp CreateResponse taskJSON, _ := json.Marshal(&task) @@ -3237,17 +3313,18 @@ func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, err fillSite(&p, site) data, status, err := c.PostRequest("/tasks/create", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Task returns task @@ -3260,7 +3337,7 @@ func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, err // // data, status, err := client.Task(12) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3271,21 +3348,22 @@ func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, err // if data.Success == true { // fmt.Printf("%v\n", data.Task) // } -func (c *Client) Task(id int) (TaskResponse, int, errs.Failure) { +func (c *Client) Task(id int) (TaskResponse, int, *errs.Failure) { var resp TaskResponse data, status, err := c.GetRequest(fmt.Sprintf("/tasks/%d", id)) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // TaskEdit edit a task @@ -3301,14 +3379,14 @@ func (c *Client) Task(id int) (TaskResponse, int, errs.Failure) { // Text: "task №2", // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse var uid = strconv.Itoa(task.ID) @@ -3321,17 +3399,18 @@ func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, e fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/tasks/%s/edit", uid), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // UserGroups returns list of user groups @@ -3344,7 +3423,7 @@ func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, e // // data, status, err := client.UserGroups(v5.UserGroupsRequest{Page: 1}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3355,23 +3434,24 @@ func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, e // for _, value := range data.Groups { // fmt.Printf("%v\n", value) // } -func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, int, errs.Failure) { +func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, int, *errs.Failure) { var resp UserGroupsResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/user-groups?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Users returns list of users matched the specified filters @@ -3384,7 +3464,7 @@ func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, i // // data, status, err := client.Users(v5.UsersRequest{Filter: v5.UsersFilter{Active: 1}, Page: 1}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3395,23 +3475,24 @@ func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, i // for _, value := range data.Users { // fmt.Printf("%v\n", value) // } -func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, errs.Failure) { +func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, *errs.Failure) { var resp UsersResponse params, _ := query.Values(parameters) data, status, err := c.GetRequest(fmt.Sprintf("/users?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // User returns information about user @@ -3424,7 +3505,7 @@ func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, errs.Failur // // data, status, err := client.User(12) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3435,21 +3516,22 @@ func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, errs.Failur // if data.Success == true { // fmt.Printf("%v\n", data.User) // } -func (c *Client) User(id int) (UserResponse, int, errs.Failure) { +func (c *Client) User(id int) (UserResponse, int, *errs.Failure) { var resp UserResponse data, status, err := c.GetRequest(fmt.Sprintf("/users/%d", id)) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // UserStatus change user status @@ -3462,14 +3544,14 @@ func (c *Client) User(id int) (UserResponse, int, errs.Failure) { // // data, status, err := client.UserStatus(12, "busy") // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse p := url.Values{ @@ -3477,37 +3559,39 @@ func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, err } data, st, err := c.PostRequest(fmt.Sprintf("/users/%d/status", id), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, st, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, st, buildErr(data) + buildErr(data, err) + return resp, st, err } - return resp, st, err + return resp, st, nil } // StaticticsUpdate updates statistics // // For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-statistic-update -func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { +func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse data, status, err := c.GetRequest("/statistic/update") - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) if resp.Success == false { - return resp, status, buildErr(data) + buildErr(data, err) + return resp, status, err } - return resp, status, err + return resp, status, nil } // Costs returns costs list @@ -3525,7 +3609,7 @@ func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3536,20 +3620,25 @@ func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, errs.Failure) { // for _, value := range data.Costs { // fmt.Printf("%v\n", value.Summ) // } -func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, errs.Failure) { +func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, *errs.Failure) { var resp CostsResponse params, _ := query.Values(costs) data, status, err := c.GetRequest(fmt.Sprintf("/costs?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CostCreate create an cost @@ -3574,7 +3663,7 @@ func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, errs.Failure) { // "store" // ) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3585,7 +3674,7 @@ func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, errs.Failure) { // If data.Success == true { // fmt.Printf("%v", data.ID) // } -func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, int, errs.Failure) { +func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, int, *errs.Failure) { var resp CreateResponse costJSON, _ := json.Marshal(&cost) @@ -3597,13 +3686,18 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in fillSite(&p, site) data, status, err := c.PostRequest("/costs/create", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CostsDelete removes a cost @@ -3616,7 +3710,7 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in // // data, status, err := client.client.CostsDelete([]int{1, 2, 3, 48, 49, 50}) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3627,7 +3721,7 @@ func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, in // If data.Success == true { // fmt.Printf("Not removed costs: %v", data.NotRemovedIds) // } -func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, errs.Failure) { +func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, *errs.Failure) { var resp CostsDeleteResponse costJSON, _ := json.Marshal(&ids) @@ -3637,13 +3731,18 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, errs.Failure) } data, status, err := c.PostRequest("/costs/delete", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CostsUpload batch costs upload @@ -3673,7 +3772,7 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, errs.Failure) // } // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3684,7 +3783,7 @@ func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, errs.Failure) // If data.Success == true { // fmt.Printf("Uploaded costs: %v", data.UploadedCosts) // } -func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, errs.Failure) { +func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, *errs.Failure) { var resp CostsUploadResponse costJSON, _ := json.Marshal(&cost) @@ -3694,13 +3793,18 @@ func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, errs. } data, status, err := c.PostRequest("/costs/upload", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // Cost returns information about specified cost @@ -3713,7 +3817,7 @@ func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, errs. // // data, status, err := client.Cost(1) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3724,18 +3828,23 @@ func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, errs. // If data.Success == true { // fmt.Printf("%v", data.Cost) // } -func (c *Client) Cost(id int) (CostResponse, int, errs.Failure) { +func (c *Client) Cost(id int) (CostResponse, int, *errs.Failure) { var resp CostResponse data, status, err := c.GetRequest(fmt.Sprintf("/costs/%d", id)) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CostDelete removes cost @@ -3748,14 +3857,14 @@ func (c *Client) Cost(id int) (CostResponse, int, errs.Failure) { // // data, status, err := client.CostDelete(1) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // // if status >= http.StatusBadRequest { // fmt.Printf("%v", err.ApiErr()) // } -func (c *Client) CostDelete(id int) (SuccessfulResponse, int, errs.Failure) { +func (c *Client) CostDelete(id int) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse costJSON, _ := json.Marshal(&id) @@ -3766,13 +3875,18 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, errs.Failure) { data, status, err := c.PostRequest(fmt.Sprintf("/costs/%d/delete", id), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CostEdit edit a cost @@ -3790,7 +3904,7 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, errs.Failure) { // CostItem: "seo", // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3801,7 +3915,7 @@ func (c *Client) CostDelete(id int) (SuccessfulResponse, int, errs.Failure) { // If data.Success == true { // fmt.Printf("%v", data.Id) // } -func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateResponse, int, errs.Failure) { +func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateResponse, int, *errs.Failure) { var resp CreateResponse costJSON, _ := json.Marshal(&cost) @@ -3813,13 +3927,18 @@ func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateRespon fillSite(&p, site) data, status, err := c.PostRequest(fmt.Sprintf("/costs/%d/edit", id), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CustomFields returns list of custom fields @@ -3835,7 +3954,7 @@ func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateRespon // Entity: "customer", // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3846,20 +3965,25 @@ func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateRespon // for _, value := range data.CustomFields { // fmt.Printf("%v\n", value) // } -func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsResponse, int, errs.Failure) { +func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsResponse, int, *errs.Failure) { var resp CustomFieldsResponse params, _ := query.Values(customFields) data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CustomDictionaries returns list of custom directory @@ -3876,7 +4000,7 @@ func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsRes // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3887,20 +4011,25 @@ func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsRes // for _, value := range data.CustomDictionaries { // fmt.Printf("%v\n", value.Elements) // } -func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest) (CustomDictionariesResponse, int, errs.Failure) { +func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest) (CustomDictionariesResponse, int, *errs.Failure) { var resp CustomDictionariesResponse params, _ := query.Values(customDictionaries) data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/dictionaries?%s", params.Encode())) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CustomDictionariesCreate creates a custom dictionary @@ -3926,7 +4055,7 @@ func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3937,7 +4066,7 @@ func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (CustomResponse, int, errs.Failure) { +func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (CustomResponse, int, *errs.Failure) { var resp CustomResponse costJSON, _ := json.Marshal(&customDictionary) @@ -3948,13 +4077,18 @@ func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (Cu data, status, err := c.PostRequest("/custom-fields/dictionaries/create", p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CustomDictionary returns information about dictionary @@ -3967,7 +4101,7 @@ func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (Cu // // data, status, err := client.CustomDictionary("courier-profiles") // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -3978,18 +4112,23 @@ func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (Cu // If data.Success == true { // fmt.Printf("%v", data.CustomDictionary.Name) // } -func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, errs.Failure) { +func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, *errs.Failure) { var resp CustomDictionaryResponse data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/dictionaries/%s", code)) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CustomDictionaryEdit edit custom dictionary @@ -4015,7 +4154,7 @@ func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, e // }, // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -4026,7 +4165,7 @@ func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, e // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (CustomResponse, int, errs.Failure) { +func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (CustomResponse, int, *errs.Failure) { var resp CustomResponse costJSON, _ := json.Marshal(&customDictionary) @@ -4036,13 +4175,18 @@ func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (Custom } data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/dictionaries/%s/edit", customDictionary.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CustomFieldsCreate creates custom field @@ -4061,7 +4205,7 @@ func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (Custom // DisplayArea: "customer", // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -4072,7 +4216,7 @@ func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (Custom // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, int, errs.Failure) { +func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, int, *errs.Failure) { var resp CustomResponse costJSON, _ := json.Marshal(&customFields) @@ -4083,13 +4227,18 @@ func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/create", customFields.Entity), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CustomField returns information about custom fields @@ -4102,7 +4251,7 @@ func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, // // data, status, err := client.CustomField("order", "first-order") // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -4113,18 +4262,23 @@ func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, // If data.Success == true { // fmt.Printf("%v", data.CustomField) // } -func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, errs.Failure) { +func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, *errs.Failure) { var resp CustomFieldResponse data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/%s/%s", entity, code)) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } // CustomFieldEdit list method @@ -4141,7 +4295,7 @@ func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, err // DisplayArea: "delivery", // }) // -// if err.RuntimeErr != nil { +// if err.Error() != "" { // fmt.Printf("%v", err.RuntimeErr) // } // @@ -4152,7 +4306,7 @@ func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, err // If data.Success == true { // fmt.Printf("%v", data.Code) // } -func (c *Client) CustomFieldEdit(customFields CustomFields) (CustomResponse, int, errs.Failure) { +func (c *Client) CustomFieldEdit(customFields CustomFields) (CustomResponse, int, *errs.Failure) { var resp CustomResponse costJSON, _ := json.Marshal(&customFields) @@ -4163,11 +4317,16 @@ func (c *Client) CustomFieldEdit(customFields CustomFields) (CustomResponse, int data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/%s/%s/edit", customFields.Entity, customFields.Code), p) - if err.RuntimeErr != nil { + if err.Error() != "" { return resp, status, err } json.Unmarshal(data, &resp) - return resp, status, err + if resp.Success == false { + buildErr(data, err) + return resp, status, err + } + + return resp, status, nil } diff --git a/v5/client_test.go b/v5/client_test.go index dbb4301..591ca2d 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -65,12 +65,16 @@ func badurlclient() *Client { return New(badURL, os.Getenv("RETAILCRM_KEY")) } -func badkeyclient() *Client { - return New(os.Getenv("RETAILCRM_URL"), "1234567890") -} - func TestGetRequest(t *testing.T) { c := client() + + defer gock.Off() + + gock.New(crmURL). + Get("/api/v5/fake-method"). + Reply(404). + BodyString(`{"success": false, "errorMsg" : "Method not found"}`) + _, status, _ := c.GetRequest("/fake-method") if status != http.StatusNotFound { @@ -80,6 +84,14 @@ func TestGetRequest(t *testing.T) { func TestPostRequest(t *testing.T) { c := client() + + defer gock.Off() + + gock.New(crmURL). + Post("/api/v5/fake-method"). + Reply(404). + BodyString(`{"success": false, "errorMsg" : "Method not found"}`) + _, status, _ := c.PostRequest("/fake-method", url.Values{}) if status != http.StatusNotFound { @@ -90,8 +102,15 @@ func TestPostRequest(t *testing.T) { func TestClient_ApiVersionsVersions(t *testing.T) { c := client() + defer gock.Off() + + gock.New(crmURL). + Get("/api/api-versions"). + Reply(200). + BodyString(`{"success": true, "versions" : ["1.0", "4.0", "3.0", "4.0", "5.0"]}`) + data, status, err := c.APIVersions() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -115,7 +134,7 @@ func TestClient_ApiVersionsVersionsBadUrl(t *testing.T) { BodyString(`{"success": false, "errorMsg" : "Account does not exist"}`) data, status, err := c.APIVersions() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -136,10 +155,10 @@ func TestClient_ApiCredentialsCredentialsBadKey(t *testing.T) { Reply(403). BodyString(`{"success": false, "errorMsg": "Wrong \"apiKey\" value"}`) - c := badkeyclient() + c := client() data, status, err := c.APICredentials() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -163,7 +182,7 @@ func TestClient_ApiCredentialsCredentials(t *testing.T) { c := client() data, status, err := c.APICredentials() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -195,7 +214,7 @@ func TestClient_CustomersCustomers(t *testing.T) { Page: 3, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -225,7 +244,7 @@ func TestClient_CustomersCustomers_Fail(t *testing.T) { }, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -270,7 +289,7 @@ func TestClient_CustomerChange(t *testing.T) { BodyString(`{"success": true, "id": 123}`) cr, sc, err := c.CustomerCreate(f) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -300,7 +319,7 @@ func TestClient_CustomerChange(t *testing.T) { BodyString(`{"success": true}`) ed, se, err := c.CustomerEdit(f, "id") - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -319,7 +338,7 @@ func TestClient_CustomerChange(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.Customer(f.ExternalID, "externalId", "") - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -355,7 +374,7 @@ func TestClient_CustomerChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Parameter 'externalId' in 'customer' is missing"}`) cr, sc, err := c.CustomerCreate(f) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -385,7 +404,7 @@ func TestClient_CustomerChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) ed, se, err := c.CustomerEdit(f, "id") - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -404,7 +423,7 @@ func TestClient_CustomerChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) data, status, err := c.Customer(codeFail, "externalId", "") - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -446,7 +465,7 @@ func TestClient_CustomersUpload(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.CustomersUpload(customers) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -479,7 +498,7 @@ func TestClient_CustomersUpload_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Customers are loaded with errors"}`) data, status, err := c.CustomersUpload(customers) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -516,7 +535,7 @@ func TestClient_CustomersCombine(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.CustomersCombine(customers, resultCustomer) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -553,7 +572,7 @@ func TestClient_CustomersCombine_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Invalid input parameters"}`) data, status, err := c.CustomersCombine([]Customer{{}, {}}, Customer{}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -590,7 +609,7 @@ func TestClient_CustomersFixExternalIds(t *testing.T) { BodyString(`{"success": true}`) fx, fe, err := c.CustomersFixExternalIds(customers) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -624,7 +643,7 @@ func TestClient_CustomersFixExternalIds_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"id": "ID must be an integer"}}`) data, status, err := c.CustomersFixExternalIds(customers) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -653,7 +672,7 @@ func TestClient_CustomersHistory(t *testing.T) { BodyString(`{"success": true, "history": [{"id": 1}]}`) data, status, err := c.CustomersHistory(f) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -687,7 +706,7 @@ func TestClient_CustomersHistory_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"children[startDate]": "Значение недопустимо."}}`) data, status, err := c.CustomersHistory(f) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -712,7 +731,7 @@ func TestClient_NotesNotes(t *testing.T) { BodyString(`{"success": true, "notes": [{"id": 1}]}`) data, status, err := c.CustomerNotes(NotesRequest{Page: 1}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -743,7 +762,7 @@ func TestClient_NotesNotes_Fail(t *testing.T) { data, status, err := c.CustomerNotes(NotesRequest{ Filter: NotesFilter{CreatedAtFrom: "2020-13-12"}, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -783,7 +802,7 @@ func TestClient_NotesCreateDelete(t *testing.T) { BodyString(`{"success": true, "id": 1}`) noteCreateResponse, noteCreateStatus, err := c.CustomerNoteCreate(note) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -807,7 +826,7 @@ func TestClient_NotesCreateDelete(t *testing.T) { BodyString(`{"success": true}`) noteDeleteResponse, noteDeleteStatus, err := c.CustomerNoteDelete(noteCreateResponse.ID) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -845,7 +864,7 @@ func TestClient_NotesCreateDelete_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the entity format", "errors": {"customer": "Set one of the following fields: id, externalId"}}`) data, status, err := c.CustomerNoteCreate(note) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -869,7 +888,7 @@ func TestClient_NotesCreateDelete_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Note not found map"}`) noteDeleteResponse, noteDeleteStatus, err := c.CustomerNoteDelete(iCodeFail) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -895,7 +914,7 @@ func TestClient_OrdersOrders(t *testing.T) { BodyString(`{"success": true, "orders": [{"id": 1}]}`) data, status, err := c.Orders(OrdersRequest{Filter: OrdersFilter{City: "Москва"}, Page: 1}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -921,7 +940,7 @@ func TestClient_OrdersOrders_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"children[attachments]": "SThis value is not valid."}}`) data, status, err := c.Orders(OrdersRequest{Filter: OrdersFilter{Attachments: 7}}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -963,7 +982,7 @@ func TestClient_OrderChange(t *testing.T) { BodyString(`{"success": true, "id": 1}`) cr, sc, err := c.OrderCreate(f) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -993,7 +1012,7 @@ func TestClient_OrderChange(t *testing.T) { BodyString(`{"success": true}`) ed, se, err := c.OrderEdit(f, "id") - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1012,7 +1031,7 @@ func TestClient_OrderChange(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.Order(f.ExternalID, "externalId", "") - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1056,7 +1075,7 @@ func TestClient_OrderChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found map"}`) data, status, err := c.OrderEdit(f, "id") - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1098,7 +1117,7 @@ func TestClient_OrdersUpload(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.OrdersUpload(orders) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1140,7 +1159,7 @@ func TestClient_OrdersUpload_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Orders are loaded with errors"}`) data, status, err := c.OrdersUpload(orders) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1174,7 +1193,7 @@ func TestClient_OrdersCombine(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.OrdersCombine("ours", Order{ID: 1}, Order{ID: 2}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1208,7 +1227,7 @@ func TestClient_OrdersCombine_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Invalid input parameters"}`) data, status, err := c.OrdersCombine("ours", Order{}, Order{}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1244,7 +1263,7 @@ func TestClient_OrdersFixExternalIds(t *testing.T) { BodyString(`{"success": true}`) fx, fe, err := c.OrdersFixExternalIds(orders) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1277,7 +1296,7 @@ func TestClient_OrdersFixExternalIds_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Invalid input parameters"}`) data, status, err := c.OrdersFixExternalIds(orders) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1302,7 +1321,7 @@ func TestClient_OrdersHistory(t *testing.T) { BodyString(`{"success": true, "history": [{"id": 1}]}`) data, status, err := c.OrdersHistory(OrdersHistoryRequest{Filter: OrdersHistoryFilter{SinceID: 20}}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1332,7 +1351,7 @@ func TestClient_OrdersHistory_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"children[startDate]": "Значение недопустимо."}}`) data, status, err := c.OrdersHistory(OrdersHistoryRequest{Filter: OrdersHistoryFilter{StartDate: "2020-13-12"}}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1371,7 +1390,7 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { BodyString(`{"success": true, "id": 1}`) paymentCreateResponse, status, err := c.OrderPaymentCreate(f) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1401,7 +1420,7 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { BodyString(`{"success": true}`) paymentEditResponse, status, err := c.OrderPaymentEdit(k, "id") - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1425,7 +1444,7 @@ func TestClient_PaymentCreateEditDelete(t *testing.T) { BodyString(`{"success": true}`) paymentDeleteResponse, status, err := c.OrderPaymentDelete(paymentCreateResponse.ID) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1462,7 +1481,7 @@ func TestClient_PaymentCreateEditDelete_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the entity format", "errors": {"order": "Set one of the following fields: id, externalId, number"}}`) data, status, err := c.OrderPaymentCreate(f) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1492,7 +1511,7 @@ func TestClient_PaymentCreateEditDelete_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Payment not found"}`) paymentEditResponse, status, err := c.OrderPaymentEdit(k, "id") - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1516,7 +1535,7 @@ func TestClient_PaymentCreateEditDelete_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Payment not found"}`) paymentDeleteResponse, status, err := c.OrderPaymentDelete(iCodeFail) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1548,7 +1567,7 @@ func TestClient_TasksTasks(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.Tasks(f) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1578,7 +1597,7 @@ func TestClient_TasksTasks_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) data, status, err := c.Tasks(f) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1613,7 +1632,7 @@ func TestClient_TaskChange(t *testing.T) { BodyString(`{"success": true, "id": 1}`) cr, sc, err := c.TaskCreate(f) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1634,7 +1653,7 @@ func TestClient_TaskChange(t *testing.T) { BodyString(`{"success": true}`) gt, sg, err := c.Task(f.ID) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1659,7 +1678,7 @@ func TestClient_TaskChange(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.TaskEdit(f) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1696,7 +1715,7 @@ func TestClient_TaskChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Task is not loaded", "errors": {"performerId": "This value should not be blank."}}`) data, status, err := c.TaskEdit(f) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1722,7 +1741,7 @@ func TestClient_UsersUsers(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.Users(UsersRequest{Filter: UsersFilter{Active: 1}, Page: 1}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1749,7 +1768,7 @@ func TestClient_UsersUsers_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"active": "he value you selected is not a valid choice."}}`) data, status, err := c.Users(UsersRequest{Filter: UsersFilter{Active: 3}, Page: 1}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1773,7 +1792,7 @@ func TestClient_UsersUser(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.User(user) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1798,7 +1817,7 @@ func TestClient_UsersUser_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) data, status, err := c.User(iCodeFail) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1823,7 +1842,7 @@ func TestClient_UsersGroups(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.UserGroups(UserGroupsRequest{Page: 1}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1853,7 +1872,7 @@ func TestClient_UsersUpdate(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.UserStatus(user, "busy") - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1884,7 +1903,7 @@ func TestClient_UsersUpdate_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) data, status, err := c.UserStatus(iCodeFail, "busy") - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1908,7 +1927,7 @@ func TestClient_StaticticsUpdate(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.StaticticsUpdate() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1932,7 +1951,7 @@ func TestClient_Countries(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.Couriers() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1956,7 +1975,7 @@ func TestClient_CostGroups(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.CostGroups() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -1980,7 +1999,7 @@ func TestClient_CostItems(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.CostItems() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2004,7 +2023,7 @@ func TestClient_Couriers(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.Couriers() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2028,7 +2047,7 @@ func TestClient_DeliveryService(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.DeliveryServices() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2052,7 +2071,7 @@ func TestClient_DeliveryTypes(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.DeliveryTypes() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2076,7 +2095,7 @@ func TestClient_LegalEntities(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.LegalEntities() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2100,7 +2119,7 @@ func TestClient_OrderMethods(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.OrderMethods() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2124,7 +2143,7 @@ func TestClient_OrderTypes(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.OrderTypes() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2148,7 +2167,7 @@ func TestClient_PaymentStatuses(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.PaymentStatuses() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2172,7 +2191,7 @@ func TestClient_PaymentTypes(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.PaymentTypes() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2196,7 +2215,7 @@ func TestClient_PriceTypes(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.PriceTypes() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2220,7 +2239,7 @@ func TestClient_ProductStatuses(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.ProductStatuses() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2244,7 +2263,7 @@ func TestClient_Statuses(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.Statuses() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2268,7 +2287,7 @@ func TestClient_StatusGroups(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.StatusGroups() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2292,7 +2311,7 @@ func TestClient_Sites(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.Sites() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2316,7 +2335,7 @@ func TestClient_Stores(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.Stores() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2357,7 +2376,7 @@ func TestClient_CostGroupItemEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.CostGroupEdit(costGroup) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2392,7 +2411,7 @@ func TestClient_CostGroupItemEdit(t *testing.T) { BodyString(`{"success": true}`) idata, st, err := c.CostItemEdit(costItem) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2432,7 +2451,7 @@ func TestClient_CostGroupItemEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) data, status, err := c.CostGroupEdit(costGroup) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2467,7 +2486,7 @@ func TestClient_CostGroupItemEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) idata, st, err := c.CostItemEdit(costItem) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2506,7 +2525,7 @@ func TestClient_Courier(t *testing.T) { BodyString(`{"success": true, "id": 1}`) data, st, err := c.CourierCreate(cur) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2535,7 +2554,7 @@ func TestClient_Courier(t *testing.T) { BodyString(`{"success": true}`) idata, st, err := c.CourierEdit(cur) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2568,7 +2587,7 @@ func TestClient_Courier_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the entity format", "errors": {"firstName": "Specify the first name"}}`) data, st, err := c.CourierCreate(Courier{}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2595,7 +2614,7 @@ func TestClient_Courier_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "An attempt was made to edit a nonexistent record"}`) idata, st, err := c.CourierEdit(cur) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2633,7 +2652,7 @@ func TestClient_DeliveryServiceEdit(t *testing.T) { BodyString(`{"success": true, "id": 1}`) data, st, err := c.DeliveryServiceEdit(deliveryService) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2670,7 +2689,7 @@ func TestClient_DeliveryServiceEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.DeliveryServiceEdit(deliveryService) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2713,7 +2732,7 @@ func TestClient_DeliveryTypeEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.DeliveryTypeEdit(deliveryType) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2754,7 +2773,7 @@ func TestClient_DeliveryTypeEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.DeliveryTypeEdit(deliveryType) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2792,7 +2811,7 @@ func TestClient_OrderMethodEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.OrderMethodEdit(orderMethod) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2830,7 +2849,7 @@ func TestClient_OrderMethodEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.OrderMethodEdit(orderMethod) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2869,7 +2888,7 @@ func TestClient_OrderTypeEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.OrderTypeEdit(orderType) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2906,7 +2925,7 @@ func TestClient_OrderTypeEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.OrderTypeEdit(orderType) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2947,7 +2966,7 @@ func TestClient_PaymentStatusEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.PaymentStatusEdit(paymentStatus) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -2987,7 +3006,7 @@ func TestClient_PaymentStatusEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.PaymentStatusEdit(paymentStatus) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3025,7 +3044,7 @@ func TestClient_PaymentTypeEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.PaymentTypeEdit(paymentType) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3063,7 +3082,7 @@ func TestClient_PaymentTypeEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.PaymentTypeEdit(paymentType) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3100,7 +3119,7 @@ func TestClient_PriceTypeEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.PriceTypeEdit(priceType) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3136,7 +3155,7 @@ func TestClient_PriceTypeEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.PriceTypeEdit(priceType) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3174,7 +3193,7 @@ func TestClient_ProductStatusEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.ProductStatusEdit(productStatus) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3211,7 +3230,7 @@ func TestClient_ProductStatusEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.ProductStatusEdit(productStatus) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3249,7 +3268,7 @@ func TestClient_StatusEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.StatusEdit(status) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3288,7 +3307,7 @@ func TestClient_StatusEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.StatusEdit(status) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3326,7 +3345,7 @@ func TestClient_SiteEdit(t *testing.T) { BodyString(`{"success": true}`) data, _, err := c.SiteEdit(site) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3360,7 +3379,7 @@ func TestClient_SiteEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Method Not Allowed"}`) data, _, err := c.SiteEdit(site) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3396,7 +3415,7 @@ func TestClient_StoreEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.StoreEdit(store) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3435,7 +3454,7 @@ func TestClient_StoreEdit_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) data, st, err := c.StoreEdit(store) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3459,7 +3478,7 @@ func TestClient_Units(t *testing.T) { BodyString(`{"success": true, "units": []}`) data, st, err := c.Units() - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3478,11 +3497,11 @@ func TestClient_UnitsEdit(t *testing.T) { defer gock.Off() unit := Unit{ - Code: RandomString(5), - Name: RandomString(5), - Sym: RandomString(2), - Default: false, - Active: true, + Code: RandomString(5), + Name: RandomString(5), + Sym: RandomString(2), + Default: false, + Active: true, } jr, _ := json.Marshal(&unit) @@ -3499,7 +3518,7 @@ func TestClient_UnitsEdit(t *testing.T) { BodyString(`{"success": true}`) data, st, err := c.UnitEdit(unit) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3518,14 +3537,14 @@ func TestClient_UnitEdit_Fail(t *testing.T) { defer gock.Off() unit := Unit{ - Name: RandomString(5), - Active: false, + Name: RandomString(5), + Active: false, } jr, _ := json.Marshal(&unit) p := url.Values{ - "store": {string(jr[:])}, + "unit": {string(jr[:])}, } gock.New(crmURL). @@ -3533,10 +3552,10 @@ func TestClient_UnitEdit_Fail(t *testing.T) { MatchType("url"). BodyString(p.Encode()). Reply(404). - BodyString(`{"success": false, "errorMsg": "API method not found"}`) + BodyString(`{"success": false, "errorMsg": "Method not found"}`) data, st, err := c.UnitEdit(unit) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3573,7 +3592,7 @@ func TestClient_PackChange(t *testing.T) { BodyString(`{"success": true, "id": 1}`) p, status, err := c.PackCreate(pack) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3591,7 +3610,7 @@ func TestClient_PackChange(t *testing.T) { BodyString(`{"success": true}`) s, status, err := c.Pack(p.ID) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3617,7 +3636,7 @@ func TestClient_PackChange(t *testing.T) { BodyString(`{"success": true}`) e, status, err := c.PackEdit(Pack{ID: p.ID, Quantity: 2}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3636,7 +3655,7 @@ func TestClient_PackChange(t *testing.T) { BodyString(`{"success": true}`) d, status, err := c.PackDelete(p.ID) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3674,7 +3693,7 @@ func TestClient_PackChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the entity format"}`) p, status, err := c.PackCreate(pack) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3692,7 +3711,7 @@ func TestClient_PackChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the entity format"}`) s, status, err := c.Pack(iCodeFail) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3718,7 +3737,7 @@ func TestClient_PackChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Pack with id 123123 not found"}`) e, status, err := c.PackEdit(Pack{ID: iCodeFail, Quantity: 2}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3737,7 +3756,7 @@ func TestClient_PackChange_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Pack not found"}`) d, status, err := c.PackDelete(iCodeFail) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3762,7 +3781,7 @@ func TestClient_PacksHistory(t *testing.T) { BodyString(`{"success": true, "history": [{"id": 1}]}`) data, status, err := c.PacksHistory(PacksHistoryRequest{Filter: OrdersHistoryFilter{SinceID: 5}}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3792,7 +3811,7 @@ func TestClient_PacksHistory_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) data, status, err := c.PacksHistory(PacksHistoryRequest{Filter: OrdersHistoryFilter{StartDate: "2020-13-12"}}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3817,7 +3836,7 @@ func TestClient_Packs(t *testing.T) { BodyString(`{"success": true}`) data, status, err := c.Packs(PacksRequest{Filter: PacksFilter{}, Page: 1}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3843,7 +3862,7 @@ func TestClient_Packs_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) data, status, err := c.Packs(PacksRequest{Filter: PacksFilter{ShipmentDateFrom: "2020-13-12"}}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3869,7 +3888,7 @@ func TestClient_Inventories(t *testing.T) { BodyString(`{"success": true, "id": 1}`) data, status, err := c.Inventories(InventoriesRequest{Filter: InventoriesFilter{Details: 1}, Page: 1}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3895,7 +3914,7 @@ func TestClient_Inventories_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) data, status, err := c.Inventories(InventoriesRequest{Filter: InventoriesFilter{Sites: []string{codeFail}}}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3919,7 +3938,7 @@ func TestClient_Segments(t *testing.T) { BodyString(`{"success": true, "id": 1}`) data, status, err := c.Segments(SegmentsRequest{}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3945,7 +3964,7 @@ func TestClient_Segments_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) data, status, err := c.Segments(SegmentsRequest{Filter: SegmentsFilter{Active: 3}}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -3991,7 +4010,7 @@ func TestClient_IntegrationModule(t *testing.T) { BodyString(`{"success": true}`) m, status, err := c.IntegrationModuleEdit(integrationModule) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4009,7 +4028,7 @@ func TestClient_IntegrationModule(t *testing.T) { BodyString(`{"success": true}`) g, status, err := c.IntegrationModule(code) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4054,7 +4073,7 @@ func TestClient_IntegrationModule_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) m, status, err := c.IntegrationModuleEdit(integrationModule) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4072,7 +4091,7 @@ func TestClient_IntegrationModule_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) g, status, err := c.IntegrationModule(code) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4101,7 +4120,7 @@ func TestClient_ProductsGroup(t *testing.T) { Active: 1, }, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4131,7 +4150,7 @@ func TestClient_ProductsGroup_Fail(t *testing.T) { Active: 3, }, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4162,7 +4181,7 @@ func TestClient_Products(t *testing.T) { MinPrice: 1, }, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4190,7 +4209,7 @@ func TestClient_Products_Fail(t *testing.T) { g, status, err := c.Products(ProductsRequest{ Filter: ProductsFilter{Active: 3}, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4222,7 +4241,7 @@ func TestClient_ProductsProperties(t *testing.T) { Sites: sites, }, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4251,7 +4270,7 @@ func TestClient_DeliveryShipments(t *testing.T) { DateFrom: "2017-10-10", }, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4280,7 +4299,7 @@ func TestClient_DeliveryShipments_Fail(t *testing.T) { Stores: []string{codeFail}, }, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4320,7 +4339,7 @@ func TestClient_Cost(t *testing.T) { data, status, err := c.CostCreate(costRecord) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4350,7 +4369,7 @@ func TestClient_Cost(t *testing.T) { Page: 1, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4369,7 +4388,7 @@ func TestClient_Cost(t *testing.T) { cost, status, err := c.Cost(id) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4400,7 +4419,7 @@ func TestClient_Cost(t *testing.T) { costEdit, status, err := c.CostEdit(id, costRecord) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4427,7 +4446,7 @@ func TestClient_Cost(t *testing.T) { costDelete, status, err := c.CostDelete(id) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4466,7 +4485,7 @@ func TestClient_Cost_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Cost is not loaded"}`) data, status, err := c.CostCreate(costRecord) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4474,7 +4493,7 @@ func TestClient_Cost_Fail(t *testing.T) { t.Error(statusFail) } - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4489,7 +4508,7 @@ func TestClient_Cost_Fail(t *testing.T) { costs, status, err := c.Costs(CostsRequest{ Filter: CostsFilter{Sites: []string{codeFail}}, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4507,7 +4526,7 @@ func TestClient_Cost_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) cost, status, err := c.Cost(id) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4538,7 +4557,7 @@ func TestClient_Cost_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Cost is not loaded"}`) costEdit, status, err := c.CostEdit(id, costRecord) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4563,7 +4582,7 @@ func TestClient_Cost_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) costDelete, status, err := c.CostDelete(id) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4616,7 +4635,7 @@ func TestClient_CostsUpload(t *testing.T) { data, status, err := c.CostsUpload(costsUpload) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4645,7 +4664,7 @@ func TestClient_CostsUpload(t *testing.T) { BodyString(`{"success": true}`) costsDelete, status, err := c.CostsDelete(ids) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4690,7 +4709,7 @@ func TestClient_CostsUpload_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Costs are loaded with errors"}`) data, status, err := c.CostsUpload(costsUpload) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4718,7 +4737,7 @@ func TestClient_CostsUpload_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Expected array, but got NULL: null"}`) costsDelete, status, err := c.CostsDelete(ids) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4743,7 +4762,7 @@ func TestClient_CustomFields(t *testing.T) { data, status, err := c.CustomFields(CustomFieldsRequest{}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4768,7 +4787,7 @@ func TestClient_CustomFields_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) data, status, err := c.CustomFields(CustomFieldsRequest{Filter: CustomFieldsFilter{Type: codeFail}}) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4814,7 +4833,7 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { data, status, err := c.CustomDictionariesCreate(customDictionary) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4842,7 +4861,7 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { Page: 1, }) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4862,7 +4881,7 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { cd, status, err := c.CustomDictionary(code) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4893,7 +4912,7 @@ func TestClient_CustomDictionariesCreate(t *testing.T) { cde, status, err := c.CustomDictionaryEdit(customDictionary) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4936,7 +4955,7 @@ func TestClient_CustomDictionariesCreate_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) data, status, err := c.CustomDictionariesCreate(customDictionary) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4950,7 +4969,7 @@ func TestClient_CustomDictionariesCreate_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) cd, status, err := c.CustomDictionary(codeFail) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -4979,7 +4998,7 @@ func TestClient_CustomDictionariesCreate_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) cde, status, err := c.CustomDictionaryEdit(customDictionary) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -5021,7 +5040,7 @@ func TestClient_CustomFieldsCreate(t *testing.T) { data, status, err := c.CustomFieldsCreate(customFields) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -5041,7 +5060,7 @@ func TestClient_CustomFieldsCreate(t *testing.T) { customField, status, err := c.CustomField("order", codeCustomField) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -5070,7 +5089,7 @@ func TestClient_CustomFieldsCreate(t *testing.T) { customFieldEdit, status, err := c.CustomFieldEdit(customFields) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -5111,7 +5130,7 @@ func TestClient_CustomFieldsCreate_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Errors in the input parameters"}`) data, status, err := c.CustomFieldsCreate(customFields) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -5129,7 +5148,7 @@ func TestClient_CustomFieldsCreate_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "Not found"}`) customField, status, err := c.CustomField("order", codeCustomField) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) } @@ -5157,7 +5176,7 @@ func TestClient_CustomFieldsCreate_Fail(t *testing.T) { BodyString(`{"success": false, "errorMsg": "API method not found"}`) customFieldEdit, status, err := c.CustomFieldEdit(customFields) - if err.RuntimeErr != nil { + if err.Error() != "" { t.Errorf("%v", err.Error()) }