mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-29 21:54:13 +01:00
Merge pull request #8836 from wy65701436/update-quota-error
Revise quota errors to make it more readable
This commit is contained in:
commit
7262cc4c1a
@ -1308,6 +1308,8 @@ paths:
|
||||
description: Invalid image values provided.
|
||||
'401':
|
||||
description: User has no permission to the source project or destination project.
|
||||
'403':
|
||||
description: Forbiden as quota exceeded.
|
||||
'404':
|
||||
description: Project or repository not found.
|
||||
'409':
|
||||
@ -5146,7 +5148,7 @@ definitions:
|
||||
allOf:
|
||||
- $ref: '#/definitions/ChartAPIError'
|
||||
ForbiddenChartAPIError:
|
||||
description: Operation is forbidden
|
||||
description: Operation is forbidden or quota exceeded
|
||||
type: object
|
||||
allOf:
|
||||
- $ref: '#/definitions/ChartAPIError'
|
||||
|
@ -79,14 +79,14 @@ func (e *ResourceOverflow) Error() string {
|
||||
)
|
||||
|
||||
if e.NewUsed > e.CurrentUsed {
|
||||
op = "add"
|
||||
op = "adding"
|
||||
delta = e.NewUsed - e.CurrentUsed
|
||||
} else {
|
||||
op = "subtract"
|
||||
op = "subtracting"
|
||||
delta = e.CurrentUsed - e.NewUsed
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s %s of %s resource overflow the hard limit, current usage is %s and hard limit is %s",
|
||||
return fmt.Sprintf("%s %s of %s resource, which when updated to current usage of %s will exceed the configured upper limit of %s.",
|
||||
op, resource.FormatValue(delta), resource,
|
||||
resource.FormatValue(e.CurrentUsed), resource.FormatValue(e.HardLimit))
|
||||
}
|
||||
|
@ -505,6 +505,10 @@ func (ra *RepositoryAPI) Retag() {
|
||||
Repo: repo,
|
||||
Tag: request.Tag,
|
||||
}); err != nil {
|
||||
if e, ok := err.(*commonhttp.Error); ok {
|
||||
ra.RenderFormattedError(e.Code, e.Message)
|
||||
return
|
||||
}
|
||||
ra.SendInternalServerError(fmt.Errorf("%v", err))
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/goharbor/harbor/src/common/quota"
|
||||
"github.com/goharbor/harbor/src/common/utils/log"
|
||||
"github.com/goharbor/harbor/src/core/middlewares/interceptor"
|
||||
"github.com/goharbor/harbor/src/core/middlewares/util"
|
||||
@ -44,7 +45,7 @@ func New(next http.Handler, builders ...interceptor.Builder) http.Handler {
|
||||
func (h *chartHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
interceptor, err := h.getInterceptor(req)
|
||||
if err != nil {
|
||||
http.Error(rw, util.MarshalError("InternalError", fmt.Sprintf("Error occurred when to handle request in chart count quota handler: %v", err)),
|
||||
http.Error(rw, fmt.Sprintf("Error occurred when to handle request in chart count quota handler: %v", err),
|
||||
http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -56,7 +57,11 @@ func (h *chartHandler) 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)
|
||||
http.Error(rw, util.MarshalError("InternalError", fmt.Sprintf("Error occurred when to handle request in chart count quota handler: %v", err)),
|
||||
if _, ok := err.(quota.Errors); ok {
|
||||
http.Error(rw, fmt.Sprintf("Quota exceeded when processing the request of %v", err), http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
http.Error(rw, fmt.Sprintf("Error occurred when to handle request in chart count quota handler: %v", err),
|
||||
http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
@ -18,10 +18,10 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/goharbor/harbor/src/common/quota"
|
||||
"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 {
|
||||
@ -58,8 +58,8 @@ 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)
|
||||
if _, ok := err.(quota.Errors); ok {
|
||||
http.Error(rw, util.MarshalError("DENIED", fmt.Sprintf("Quota exceeded when processing the request of %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)),
|
||||
|
@ -18,10 +18,10 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/goharbor/harbor/src/common/quota"
|
||||
"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 {
|
||||
@ -58,8 +58,8 @@ 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)
|
||||
if _, ok := err.(quota.Errors); ok {
|
||||
http.Error(rw, util.MarshalError("DENIED", fmt.Sprintf("Quota exceeded when processing the request of %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)),
|
||||
|
Loading…
Reference in New Issue
Block a user