mirror of
https://github.com/retailcrm/api-client-go.git
synced 2025-04-03 13:13:37 +03:00
fixed linters error
This commit is contained in:
parent
0ec1160c99
commit
8d23bb3e90
4 changed files with 230 additions and 178 deletions
351
v5/client.go
351
v5/client.go
File diff suppressed because it is too large
Load diff
30
v5/error.go
30
v5/error.go
|
@ -5,28 +5,26 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
// ApiErrorsList struct.
|
||||
type ApiErrorsList map[string]string
|
||||
const ArrowHTML = 60
|
||||
|
||||
// ApiError struct.
|
||||
type ApiError struct {
|
||||
// APIErrorsList struct.
|
||||
type APIErrorsList map[string]string
|
||||
|
||||
// APIError struct.
|
||||
type APIError struct {
|
||||
SuccessfulResponse
|
||||
ErrorMsg string `json:"errorMsg,omitempty"`
|
||||
Errors ApiErrorsList `json:"errors,omitempty"`
|
||||
Errors APIErrorsList `json:"errors,omitempty"`
|
||||
}
|
||||
|
||||
func (e *ApiError) Error() string {
|
||||
func (e *APIError) Error() string {
|
||||
return e.ErrorMsg
|
||||
}
|
||||
|
||||
func (e *ApiError) GetApiErrors() map[string]string {
|
||||
return e.Errors
|
||||
}
|
||||
func NewAPIError(dataResponse []byte) error {
|
||||
a := &APIError{}
|
||||
|
||||
func NewApiError(dataResponse []byte) error {
|
||||
a := &ApiError{}
|
||||
|
||||
if dataResponse[0] == 60 {
|
||||
if dataResponse[0] == ArrowHTML {
|
||||
a.ErrorMsg = "405 Not Allowed"
|
||||
return a
|
||||
}
|
||||
|
@ -42,13 +40,13 @@ func NewApiError(dataResponse []byte) error {
|
|||
func ErrorsHandler(errs interface{}) map[string]string {
|
||||
m := make(map[string]string)
|
||||
|
||||
switch errs.(type) {
|
||||
switch e := errs.(type) {
|
||||
case map[string]interface{}:
|
||||
for idx, val := range errs.(map[string]interface{}) {
|
||||
for idx, val := range e {
|
||||
m[idx] = val.(string)
|
||||
}
|
||||
case []interface{}:
|
||||
for idx, val := range errs.([]interface{}) {
|
||||
for idx, val := range e {
|
||||
m[strconv.Itoa(idx)] = val.(string)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package v5
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -10,9 +11,15 @@ func TestFailure_ApiErrorsSlice(t *testing.T) {
|
|||
"0": "Your account has insufficient funds to activate integration module",
|
||||
}
|
||||
|
||||
e := NewApiError(b)
|
||||
if eq := e.(*ApiError).Errors["0"] == expected["0"]; eq != true {
|
||||
t.Errorf("%+v", eq)
|
||||
var expEr *APIError
|
||||
e := NewAPIError(b)
|
||||
|
||||
if errors.As(e, &expEr) {
|
||||
if eq := expEr.Errors["0"] == expected["0"]; eq != true {
|
||||
t.Errorf("%+v", eq)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("Error must be type of APIError: %v", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,8 +29,14 @@ func TestFailure_ApiErrorsMap(t *testing.T) {
|
|||
"id": "ID must be an integer",
|
||||
}
|
||||
|
||||
e := NewApiError(b)
|
||||
if eq := expected["id"] == e.(*ApiError).Errors["id"]; eq != true {
|
||||
t.Errorf("%+v", eq)
|
||||
var expEr *APIError
|
||||
e := NewAPIError(b)
|
||||
|
||||
if errors.As(e, &expEr) {
|
||||
if eq := expected["id"] == expEr.Errors["id"]; eq != true {
|
||||
t.Errorf("%+v", eq)
|
||||
}
|
||||
} else {
|
||||
t.Errorf("Error must be type of APIError: %v", e)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ func (t Tag) MarshalJSON() ([]byte, error) {
|
|||
return json.Marshal(t.Name)
|
||||
}
|
||||
|
||||
func (a *ApiErrorsList) UnmarshalJSON(data []byte) error {
|
||||
func (a *APIErrorsList) UnmarshalJSON(data []byte) error {
|
||||
var i interface{}
|
||||
if err := json.Unmarshal(data, &i); err != nil {
|
||||
return err
|
||||
|
|
Loading…
Add table
Reference in a new issue