mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-17 07:45:24 +01:00
fix return value for blob & manifest not found
When to delete an non exist blob/manifest, the API has to return a 404 instead of 500 Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
parent
264bd02892
commit
95bee9a0cc
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user