diff --git a/.travis.yml b/.travis.yml index f39aae2..22da27f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ go: - '1.8' - '1.9' - '1.10' + - '1.11' before_install: - go get -v github.com/google/go-querystring/query - go get -v github.com/h2non/gock diff --git a/errs/error.go b/errs/error.go index 2582574..2730943 100644 --- a/errs/error.go +++ b/errs/error.go @@ -12,11 +12,11 @@ func (f *Failure) Error() string { // ApiError returns formatted string representation of the API error func (f *Failure) ApiError() string { - return fmt.Sprintf("%v", f.ApiErr) + return fmt.Sprintf("%+v", f.ApiErr) } // ApiErrors returns array of formatted strings that represents API errors -func (f *Failure) ApiErrors() map[string]string { +func (f *Failure) ApiErrors() interface{} { return f.ApiErrs } diff --git a/errs/error_test.go b/errs/error_test.go new file mode 100644 index 0000000..1527c36 --- /dev/null +++ b/errs/error_test.go @@ -0,0 +1,45 @@ +package errs + +import ( + "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"]}`) + + resp, e := ErrorResponse(b) + err.RuntimeErr = e + err.ApiErr = resp.ErrorMsg + + if resp.Errors != nil { + err.ApiErrs = resp.Errors + } + + f, ok := resp.Errors.([]interface{}) + + if !ok { + t.Errorf("%+v", f) + } + +} + +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"}}`) + + resp, e := ErrorResponse(b) + err.RuntimeErr = e + err.ApiErr = resp.ErrorMsg + + if resp.Errors != nil { + err.ApiErrs = resp.Errors + } + + f, ok := resp.Errors.(map[string]interface{}) + + if !ok { + t.Errorf("%+v", f) + } + +} diff --git a/errs/interfaces.go b/errs/interfaces.go index 371eec4..d8bedf1 100644 --- a/errs/interfaces.go +++ b/errs/interfaces.go @@ -4,5 +4,5 @@ package errs type Error interface { error ApiError() string - ApiErrors() map[string]string + ApiErrors() interface{} } diff --git a/errs/types.go b/errs/types.go index 1029675..a2705f2 100644 --- a/errs/types.go +++ b/errs/types.go @@ -4,11 +4,11 @@ package errs type Failure struct { RuntimeErr error ApiErr string - ApiErrs map[string]string + ApiErrs interface{} } // FailureResponse convert json error response into object type FailureResponse struct { - ErrorMsg string `json:"errorMsg,omitempty"` - Errors map[string]string `json:"errors,omitempty"` + ErrorMsg string `json:"errorMsg,omitempty"` + Errors interface{} `json:"errors,omitempty"` }