From 638643cda7fdef179c11252ee68319e2f882cd6a Mon Sep 17 00:00:00 2001 From: Alexandros Kosiaris Date: Wed, 16 Jun 2021 12:26:39 +0300 Subject: [PATCH] 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 --- client/request.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/client/request.go b/client/request.go index c6b5eb9e..913c5dc7 100644 --- a/client/request.go +++ b/client/request.go @@ -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