Skip to content

Commit a11d785

Browse files
Include URL and method in ErrUnexpectedStatus
This should help with debugging expected responses. Signed-off-by: Ilya Dmitrichenko <[email protected]>
1 parent 8634cd9 commit a11d785

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

remotes/errors/errors.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ var _ error = ErrUnexpectedStatus{}
2727

2828
// ErrUnexpectedStatus is returned if a registry API request returned with unexpected HTTP status
2929
type ErrUnexpectedStatus struct {
30-
Status string
31-
StatusCode int
32-
Body []byte
30+
Status string
31+
StatusCode int
32+
Body []byte
33+
RequestURL, RequestMethod string
3334
}
3435

3536
func (e ErrUnexpectedStatus) Error() string {
@@ -42,5 +43,14 @@ func NewUnexpectedStatusErr(resp *http.Response) error {
4243
if resp.Body != nil {
4344
b, _ = ioutil.ReadAll(io.LimitReader(resp.Body, 64000)) // 64KB
4445
}
45-
return ErrUnexpectedStatus{Status: resp.Status, StatusCode: resp.StatusCode, Body: b}
46+
err := ErrUnexpectedStatus{
47+
Body: b,
48+
Status: resp.Status,
49+
StatusCode: resp.StatusCode,
50+
RequestMethod: resp.Request.Method,
51+
}
52+
if resp.Request.URL != nil {
53+
err.RequestURL = resp.Request.URL.String()
54+
}
55+
return err
4656
}

0 commit comments

Comments
 (0)