mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-18 22:57:38 +01:00
Merge pull request #12386 from wy65701436/delete-blob-not-found
fix return value for blob & manifest not found
This commit is contained in:
commit
cf07ff0052
@ -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