From a117903084110922c5e242fa6f31329bc81b88a9 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Mon, 26 Sep 2022 15:35:53 +0200 Subject: HTTP: Add the body to status error --- internal/http/http.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/http/http.go b/internal/http/http.go index 3a81eb6..15e2a17 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -147,7 +147,7 @@ func HTTPMethodWithOpts( if resp.StatusCode < 200 || resp.StatusCode > 299 { // We make this a custom error because we want to extract the status code later - statusErr := &HTTPStatusError{URL: url, Status: resp.StatusCode} + statusErr := &HTTPStatusError{URL: url, Body: string(body), Status: resp.StatusCode} return resp.Header, body, &types.WrappedErrorMessage{Message: errorMessage, Err: statusErr} } @@ -157,14 +157,16 @@ func HTTPMethodWithOpts( type HTTPStatusError struct { URL string + Body string Status int } func (e *HTTPStatusError) Error() string { return fmt.Sprintf( - "failed obtaining HTTP resource: %s as it gave an unsuccesful status code: %d", + "failed obtaining HTTP resource: %s as it gave an unsuccesful status code: %d. Body: %s", e.URL, e.Status, + e.Body, ) } -- cgit v1.2.3