Move ErrorCode logic to new errcode package
Make HTTP status codes match the ErrorCode by looking it up in the Descriptors Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
parent
5f553b3cfc
commit
f565d6abb7
16 changed files with 444 additions and 405 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/docker/distribution"
|
||||
"github.com/docker/distribution/context"
|
||||
"github.com/docker/distribution/digest"
|
||||
"github.com/docker/distribution/registry/api/errcode"
|
||||
"github.com/docker/distribution/registry/api/v2"
|
||||
"github.com/gorilla/handlers"
|
||||
)
|
||||
|
@ -17,7 +18,6 @@ func blobDispatcher(ctx *Context, r *http.Request) http.Handler {
|
|||
|
||||
if err == errDigestNotAvailable {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
ctx.Errors.Push(v2.ErrorCodeDigestInvalid, err)
|
||||
})
|
||||
}
|
||||
|
@ -53,17 +53,16 @@ func (bh *blobHandler) GetBlob(w http.ResponseWriter, r *http.Request) {
|
|||
desc, err := blobs.Stat(bh, bh.Digest)
|
||||
if err != nil {
|
||||
if err == distribution.ErrBlobUnknown {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
bh.Errors.Push(v2.ErrorCodeBlobUnknown, bh.Digest)
|
||||
} else {
|
||||
bh.Errors.Push(v2.ErrorCodeUnknown, err)
|
||||
bh.Errors.Push(errcode.ErrorCodeUnknown, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err := blobs.ServeBlob(bh, w, r, desc.Digest); err != nil {
|
||||
context.GetLogger(bh).Debugf("unexpected error getting blob HTTP handler: %v", err)
|
||||
bh.Errors.Push(v2.ErrorCodeUnknown, err)
|
||||
bh.Errors.Push(errcode.ErrorCodeUnknown, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue