From a11d78578498e0669a80d871845baa118bceb7a9 Mon Sep 17 00:00:00 2001 From: Ilya Dmitrichenko Date: Thu, 11 Mar 2021 14:28:28 +0000 Subject: [PATCH] Include URL and method in `ErrUnexpectedStatus` This should help with debugging expected responses. Signed-off-by: Ilya Dmitrichenko --- remotes/errors/errors.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/remotes/errors/errors.go b/remotes/errors/errors.go index e58e4afea..519dbac10 100644 --- a/remotes/errors/errors.go +++ b/remotes/errors/errors.go @@ -27,9 +27,10 @@ var _ error = ErrUnexpectedStatus{} // ErrUnexpectedStatus is returned if a registry API request returned with unexpected HTTP status type ErrUnexpectedStatus struct { - Status string - StatusCode int - Body []byte + Status string + StatusCode int + Body []byte + RequestURL, RequestMethod string } func (e ErrUnexpectedStatus) Error() string { @@ -42,5 +43,14 @@ func NewUnexpectedStatusErr(resp *http.Response) error { if resp.Body != nil { b, _ = ioutil.ReadAll(io.LimitReader(resp.Body, 64000)) // 64KB } - return ErrUnexpectedStatus{Status: resp.Status, StatusCode: resp.StatusCode, Body: b} + err := ErrUnexpectedStatus{ + Body: b, + Status: resp.Status, + StatusCode: resp.StatusCode, + RequestMethod: resp.Request.Method, + } + if resp.Request.URL != nil { + err.RequestURL = resp.Request.URL.String() + } + return err }