add model of error for response
This commit is contained in:
parent
227c6e7d46
commit
987d9cd6de
@ -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.
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -66,6 +66,12 @@ const (
|
||||
OriginatorChannel
|
||||
)
|
||||
|
||||
type APIError string
|
||||
|
||||
func (err APIError) Error() string {
|
||||
return string(err)
|
||||
}
|
||||
|
||||
type ErrorType string
|
||||
|
||||
const (
|
||||
|
Loading…
Reference in New Issue
Block a user