1
0
Fork 0

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:
Alexandros Kosiaris 2021-06-16 12:26:39 +03:00 committed by fguillot
parent 6703e03ce6
commit 638643cda7

View file

@ -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