Merge pull request #5164 from errordeveloper/master
Improve unexpected response error handling
This commit is contained in:
commit
92009ad7a3
@ -354,7 +354,7 @@ func (pw *pushWriter) Commit(ctx context.Context, size int64, expected digest.Di
|
|||||||
switch resp.StatusCode {
|
switch resp.StatusCode {
|
||||||
case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted:
|
case http.StatusOK, http.StatusCreated, http.StatusNoContent, http.StatusAccepted:
|
||||||
default:
|
default:
|
||||||
return errors.Errorf("unexpected status: %s", resp.Status)
|
return remoteserrors.NewUnexpectedStatusErr(resp.Response)
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err := pw.tracker.GetStatus(pw.ref)
|
status, err := pw.tracker.GetStatus(pw.ref)
|
||||||
|
@ -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