1
0
mirror of synced 2024-11-24 22:16:05 +03:00

add model of error for response

This commit is contained in:
Ruslan Efanov 2022-10-25 10:47:02 +03:00
parent 227c6e7d46
commit 987d9cd6de
3 changed files with 15 additions and 1 deletions

View File

@ -674,7 +674,7 @@ func (c *MgClient) Error(info []byte) error {
values := data["errors"].([]interface{}) values := data["errors"].([]interface{})
return errors.New(values[0].(string)) return APIError(values[0].(string))
} }
// MakeTimestamp returns current unix timestamp. // MakeTimestamp returns current unix timestamp.

View File

@ -678,3 +678,11 @@ func (t *MGClientTest) Test_UploadFile() {
resp.CreatedAt = data.CreatedAt resp.CreatedAt = data.CreatedAt
t.Assert().Equal(resp, data) 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")
}

View File

@ -66,6 +66,12 @@ const (
OriginatorChannel OriginatorChannel
) )
type APIError string
func (err APIError) Error() string {
return string(err)
}
type ErrorType string type ErrorType string
const ( const (