client: Try to parse response Body on InternalServerError
Try to parse the response body from the server when an HTTP 500 is returned (i.e. http.StatusInternalServerError) as it might contain useful information. If successful, create a new error and append that information to the returned error message. Otherwise just maintain the same behavior
This commit is contained in:
parent
6703e03ce6
commit
638643cda7
1 changed files with 9 additions and 2 deletions
|
@ -104,8 +104,15 @@ func (r *request) execute(method, path string, data interface{}) (io.ReadCloser,
|
|||
response.Body.Close()
|
||||
return nil, ErrForbidden
|
||||
case http.StatusInternalServerError:
|
||||
response.Body.Close()
|
||||
return nil, ErrServerError
|
||||
defer response.Body.Close()
|
||||
|
||||
var resp errorResponse
|
||||
decoder := json.NewDecoder(response.Body)
|
||||
// If we failed to decode, just return a generic ErrServerError
|
||||
if err := decoder.Decode(&resp); err != nil {
|
||||
return nil, ErrServerError
|
||||
}
|
||||
return nil, errors.New("miniflux: internal server error: " + resp.ErrorMessage)
|
||||
case http.StatusNotFound:
|
||||
response.Body.Close()
|
||||
return nil, ErrNotFound
|
||||
|
|
Loading…
Reference in a new issue