Merge pull request #12386 from wy65701436/delete-blob-not-found

fix return value for blob & manifest not found
This commit is contained in:
Daniel Jiang 2020-07-03 11:37:31 +08:00 committed by GitHub
commit cf07ff0052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -16,6 +16,7 @@ package api
import (
"encoding/json"
"github.com/docker/distribution/registry/storage/driver"
"github.com/goharbor/harbor/src/lib/errors"
lib_http "github.com/goharbor/harbor/src/lib/http"
"net/http"
@ -38,6 +39,9 @@ func HandleBadRequest(w http.ResponseWriter, err error) {
// HandleError ...
func HandleError(w http.ResponseWriter, err error) {
if _, ok := err.(driver.PathNotFoundError); ok {
err = errors.New(nil).WithCode(errors.NotFoundCode).WithMessage(err.Error())
}
lib_http.SendError(w, err)
}

View File

@ -15,6 +15,7 @@
package api
import (
"github.com/docker/distribution/registry/storage/driver"
"github.com/goharbor/harbor/src/lib/errors"
"net/http"
"net/http/httptest"
@ -47,4 +48,10 @@ func TestHandleError(t *testing.T) {
t.Errorf("unexpected status code: %d != %d", w.Code, http.StatusInternalServerError)
}
w = httptest.NewRecorder()
HandleError(w, driver.PathNotFoundError{Path: "/blobstore/nonexist"})
if w.Code != http.StatusNotFound {
t.Errorf("unexpected status code: %d != %d", w.Code, http.StatusNotFound)
}
}