mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
commit
3ebe81de8f
@ -21,6 +21,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/common/utils/log"
|
||||
"github.com/goharbor/harbor/src/core/middlewares/interceptor"
|
||||
"github.com/goharbor/harbor/src/core/middlewares/util"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type countQuotaHandler struct {
|
||||
@ -57,6 +58,10 @@ func (h *countQuotaHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
|
||||
|
||||
if err := interceptor.HandleRequest(req); err != nil {
|
||||
log.Warningf("Error occurred when to handle request in count quota handler: %v", err)
|
||||
if strings.Contains(err.Error(), "resource overflow the hard limit") {
|
||||
http.Error(rw, util.MarshalError("DENIED", fmt.Sprintf("Not enough quota is available to process the request: %v", err)), http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
http.Error(rw, util.MarshalError("InternalError", fmt.Sprintf("Error occurred when to handle request in count quota handler: %v", err)),
|
||||
http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -202,12 +202,12 @@ func (suite *HandlerSuite) TestPutManifestFailed() {
|
||||
}()
|
||||
|
||||
next := func(w http.ResponseWriter, req *http.Request) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
}
|
||||
|
||||
dgt := digest.FromString(randomString(15)).String()
|
||||
code := doPutManifestRequest(projectID, projectName, "photon", "latest", dgt, next)
|
||||
suite.Equal(http.StatusInternalServerError, code)
|
||||
suite.Equal(http.StatusForbidden, code)
|
||||
suite.checkCountUsage(0, projectID)
|
||||
|
||||
total, err := dao.GetTotalOfArtifacts(&models.ArtifactQuery{Digest: dgt})
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/goharbor/harbor/src/common/utils/log"
|
||||
"github.com/goharbor/harbor/src/core/middlewares/interceptor"
|
||||
"github.com/goharbor/harbor/src/core/middlewares/util"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type sizeQuotaHandler struct {
|
||||
@ -57,6 +58,10 @@ func (h *sizeQuotaHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
|
||||
|
||||
if err := interceptor.HandleRequest(req); err != nil {
|
||||
log.Warningf("Error occurred when to handle request in size quota handler: %v", err)
|
||||
if strings.Contains(err.Error(), "resource overflow the hard limit") {
|
||||
http.Error(rw, util.MarshalError("DENIED", fmt.Sprintf("Not enough quota is available to process the request: %v", err)), http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
http.Error(rw, util.MarshalError("InternalError", fmt.Sprintf("Error occurred when to handle request in size quota handler: %v", err)),
|
||||
http.StatusInternalServerError)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user