From 419abe8268f9969bf95c69e5232256c8bab1c85f Mon Sep 17 00:00:00 2001 From: Nikhil Banerjee Date: Tue, 19 Apr 2022 20:44:22 +0100 Subject: [PATCH] Handle additional generic error responses from registry Signed-off-by: Nikhil Banerjee --- registry/handlers/app.go | 4 ++++ registry/handlers/manifests.go | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/registry/handlers/app.go b/registry/handlers/app.go index 0514ed22b47..5d1199c7c99 100644 --- a/registry/handlers/app.go +++ b/registry/handlers/app.go @@ -853,6 +853,10 @@ func (app *App) authorized(w http.ResponseWriter, r *http.Request, context *Cont if err := errcode.ServeJSON(w, errcode.ErrorCodeUnauthorized.WithDetail(accessRecords)); err != nil { dcontext.GetLogger(context).Errorf("error serving error json: %v (from %v)", err, context.Errors) } + case errcode.Error: + if err := errcode.ServeJSON(w, err); err != nil { + dcontext.GetLogger(context).Errorf("error serving error json: %v (from %v)", err, context.Errors) + } default: // This condition is a potential security problem either in // the configuration or whatever is backing the access diff --git a/registry/handlers/manifests.go b/registry/handlers/manifests.go index 76cfe53112c..d655f46a209 100644 --- a/registry/handlers/manifests.go +++ b/registry/handlers/manifests.go @@ -383,7 +383,13 @@ func (imh *manifestHandler) PutManifest(w http.ResponseWriter, r *http.Request) tags := imh.Repository.Tags(imh) err = tags.Tag(imh, imh.Tag, desc) if err != nil { - imh.Errors = append(imh.Errors, errcode.ErrorCodeUnknown.WithDetail(err)) + switch err := err.(type) { + case errcode.Error: + imh.Errors = append(imh.Errors, err) + default: + imh.Errors = append(imh.Errors, errcode.ErrorCodeUnknown.WithDetail(err)) + } + return }