mirror of
https://github.com/distribution/distribution.git
synced 2025-08-21 08:13:39 +00:00
Revert "registry: convert AWS S3 error to correct errcode"
This reverts commit f02edffc68a4224b466479acd009bb48484ba814.
This commit is contained in:
parent
aabf07ec65
commit
06327e35d6
@ -3,9 +3,6 @@ package errcode
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
||||||
"github.com/docker/distribution/registry/storage/driver"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServeJSON attempts to serve the errcode in a JSON envelope. It marshals err
|
// ServeJSON attempts to serve the errcode in a JSON envelope. It marshals err
|
||||||
@ -21,27 +18,13 @@ func ServeJSON(w http.ResponseWriter, err error) error {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range errs {
|
|
||||||
if err2, ok := errs[i].(Error); ok {
|
|
||||||
errs[i] = replaceError(err2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err, ok := errs[0].(ErrorCoder); ok {
|
if err, ok := errs[0].(ErrorCoder); ok {
|
||||||
sc = err.ErrorCode().Descriptor().HTTPStatusCode
|
sc = err.ErrorCode().Descriptor().HTTPStatusCode
|
||||||
}
|
}
|
||||||
case ErrorCoder:
|
case ErrorCoder:
|
||||||
if err2, ok := errs.(Error); ok {
|
|
||||||
errs = replaceError(err2)
|
|
||||||
}
|
|
||||||
|
|
||||||
sc = errs.ErrorCode().Descriptor().HTTPStatusCode
|
sc = errs.ErrorCode().Descriptor().HTTPStatusCode
|
||||||
err = Errors{err} // create an envelope.
|
err = Errors{err} // create an envelope.
|
||||||
default:
|
default:
|
||||||
if err2, ok := err.(Error); ok {
|
|
||||||
err = replaceError(err2)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We just have an unhandled error type, so just place in an envelope
|
// We just have an unhandled error type, so just place in an envelope
|
||||||
// and move along.
|
// and move along.
|
||||||
err = Errors{err}
|
err = Errors{err}
|
||||||
@ -55,29 +38,3 @@ func ServeJSON(w http.ResponseWriter, err error) error {
|
|||||||
|
|
||||||
return json.NewEncoder(w).Encode(err)
|
return json.NewEncoder(w).Encode(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func replaceError(e Error) Error {
|
|
||||||
serr, ok := e.Detail.(driver.Error)
|
|
||||||
if !ok {
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
err, ok := serr.Enclosed.(awserr.RequestFailure)
|
|
||||||
if !ok {
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
code := ErrorCodeUnknown
|
|
||||||
switch err.StatusCode() {
|
|
||||||
case http.StatusForbidden:
|
|
||||||
code = ErrorCodeDenied
|
|
||||||
case http.StatusServiceUnavailable:
|
|
||||||
code = ErrorCodeUnavailable
|
|
||||||
case http.StatusUnauthorized:
|
|
||||||
code = ErrorCodeUnauthorized
|
|
||||||
case http.StatusTooManyRequests:
|
|
||||||
code = ErrorCodeTooManyRequests
|
|
||||||
}
|
|
||||||
|
|
||||||
return code.WithDetail(err.Code())
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user