Include URL and method in ErrUnexpectedStatus
This should help with debugging expected responses. Signed-off-by: Ilya Dmitrichenko <errordeveloper@gmail.com>
This commit is contained in:
parent
8634cd9dfd
commit
a11d785784
@ -27,9 +27,10 @@ var _ error = ErrUnexpectedStatus{}
|
|||||||
|
|
||||||
// ErrUnexpectedStatus is returned if a registry API request returned with unexpected HTTP status
|
// ErrUnexpectedStatus is returned if a registry API request returned with unexpected HTTP status
|
||||||
type ErrUnexpectedStatus struct {
|
type ErrUnexpectedStatus struct {
|
||||||
Status string
|
Status string
|
||||||
StatusCode int
|
StatusCode int
|
||||||
Body []byte
|
Body []byte
|
||||||
|
RequestURL, RequestMethod string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrUnexpectedStatus) Error() string {
|
func (e ErrUnexpectedStatus) Error() string {
|
||||||
@ -42,5 +43,14 @@ func NewUnexpectedStatusErr(resp *http.Response) error {
|
|||||||
if resp.Body != nil {
|
if resp.Body != nil {
|
||||||
b, _ = ioutil.ReadAll(io.LimitReader(resp.Body, 64000)) // 64KB
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user