diff --git a/v1/client.go b/v1/client.go index c8f3c90..58210ac 100644 --- a/v1/client.go +++ b/v1/client.go @@ -674,7 +674,7 @@ func (c *MgClient) Error(info []byte) error { values := data["errors"].([]interface{}) - return errors.New(values[0].(string)) + return APIError(values[0].(string)) } // MakeTimestamp returns current unix timestamp. diff --git a/v1/client_test.go b/v1/client_test.go index 4fb112e..679bb08 100644 --- a/v1/client_test.go +++ b/v1/client_test.go @@ -678,3 +678,11 @@ func (t *MGClientTest) Test_UploadFile() { resp.CreatedAt = data.CreatedAt t.Assert().Equal(resp, data) } + +func (t *MGClientTest) Test_SuccessHandleError() { + client := t.client() + handleError := client.Error([]byte(`{"errors": ["Channel not found"]}`)) + + t.Assert().IsType(APIError(""), handleError) + t.Assert().Equal(handleError.Error(), "Channel not found") +} diff --git a/v1/types.go b/v1/types.go index 239741c..7492361 100644 --- a/v1/types.go +++ b/v1/types.go @@ -66,6 +66,12 @@ const ( OriginatorChannel ) +type APIError string + +func (err APIError) Error() string { + return string(err) +} + type ErrorType string const (