some api changes
This commit is contained in:
parent
f305f96195
commit
70fd3f71e5
11 changed files with 118 additions and 76 deletions
|
|
@ -2,13 +2,16 @@ package client
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
Message string `json:"message"`
|
||||
Status int `json:"status"`
|
||||
Err string `json:"error"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
func (e Error) Error() string {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
func decodeResp(resp *http.Response, v interface{}) error {
|
||||
|
|
@ -22,16 +25,13 @@ func decodeResp(resp *http.Response, v interface{}) error {
|
|||
}
|
||||
return json.NewDecoder(resp.Body).Decode(&v)
|
||||
}
|
||||
if resp.StatusCode == 404 {
|
||||
return ErrNotFound
|
||||
}
|
||||
var e Error
|
||||
err := json.NewDecoder(resp.Body).Decode(&e)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode >= 400 && resp.StatusCode <= 599 {
|
||||
return errors.New(e.Message)
|
||||
return e
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue