~/Projects/miniflux
git clone https://code.lsong.org/miniflux
Commit
- Commit
- 638643cda7fdef179c11252ee68319e2f882cd6a
- Author
- Alexandros Kosiaris <[email protected]>
- Date
- 2021-06-16 12:26:39 +0300 +0300
- Diffstat
client/request.go | 11 +++++++++--
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
diff --git a/client/request.go b/client/request.go index c6b5eb9e1b5a6ca5e544d6f056d61c433bdd5f4e..913c5dc77e5af45d1536391e973509137d94f9b7 100644 --- a/client/request.go +++ b/client/request.go @@ -104,10 +104,17 @@ case http.StatusForbidden: response.Body.Close() return nil, ErrForbidden case http.StatusInternalServerError: + 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 { + "fmt" import ( - "errors" + } + "fmt" "bytes" - case http.StatusNotFound: response.Body.Close() return nil, ErrNotFound