mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-23 00:57:44 +01:00
Revise quota errors to make it more readable
1, fix #8802, update the error formet 2, fix #8807, raise the real retag error to UI 3, fix #8832, raise the real chart error to chart client & ut Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
parent
a80969e7af
commit
f343b2ec45
@ -1308,6 +1308,8 @@ paths:
|
|||||||
description: Invalid image values provided.
|
description: Invalid image values provided.
|
||||||
'401':
|
'401':
|
||||||
description: User has no permission to the source project or destination project.
|
description: User has no permission to the source project or destination project.
|
||||||
|
'403':
|
||||||
|
description: Forbiden as quota exceeded.
|
||||||
'404':
|
'404':
|
||||||
description: Project or repository not found.
|
description: Project or repository not found.
|
||||||
'409':
|
'409':
|
||||||
@ -5146,7 +5148,7 @@ definitions:
|
|||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/definitions/ChartAPIError'
|
- $ref: '#/definitions/ChartAPIError'
|
||||||
ForbiddenChartAPIError:
|
ForbiddenChartAPIError:
|
||||||
description: Operation is forbidden
|
description: Operation is forbidden or quota exceeded
|
||||||
type: object
|
type: object
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/definitions/ChartAPIError'
|
- $ref: '#/definitions/ChartAPIError'
|
||||||
|
@ -79,14 +79,14 @@ func (e *ResourceOverflow) Error() string {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if e.NewUsed > e.CurrentUsed {
|
if e.NewUsed > e.CurrentUsed {
|
||||||
op = "add"
|
op = "adding"
|
||||||
delta = e.NewUsed - e.CurrentUsed
|
delta = e.NewUsed - e.CurrentUsed
|
||||||
} else {
|
} else {
|
||||||
op = "subtract"
|
op = "subtracting"
|
||||||
delta = e.CurrentUsed - e.NewUsed
|
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,
|
op, resource.FormatValue(delta), resource,
|
||||||
resource.FormatValue(e.CurrentUsed), resource.FormatValue(e.HardLimit))
|
resource.FormatValue(e.CurrentUsed), resource.FormatValue(e.HardLimit))
|
||||||
}
|
}
|
||||||
|
@ -505,6 +505,10 @@ func (ra *RepositoryAPI) Retag() {
|
|||||||
Repo: repo,
|
Repo: repo,
|
||||||
Tag: request.Tag,
|
Tag: request.Tag,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
if e, ok := err.(*commonhttp.Error); ok {
|
||||||
|
ra.RenderFormattedError(e.Code, e.Message)
|
||||||
|
return
|
||||||
|
}
|
||||||
ra.SendInternalServerError(fmt.Errorf("%v", err))
|
ra.SendInternalServerError(fmt.Errorf("%v", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/common/quota"
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/core/middlewares/interceptor"
|
"github.com/goharbor/harbor/src/core/middlewares/interceptor"
|
||||||
"github.com/goharbor/harbor/src/core/middlewares/util"
|
"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) {
|
func (h *chartHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
interceptor, err := h.getInterceptor(req)
|
interceptor, err := h.getInterceptor(req)
|
||||||
if err != nil {
|
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)
|
http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -56,7 +57,11 @@ func (h *chartHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
if err := interceptor.HandleRequest(req); err != nil {
|
if err := interceptor.HandleRequest(req); err != nil {
|
||||||
log.Warningf("Error occurred when to handle request in count quota handler: %v", err)
|
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)
|
http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/common/quota"
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/core/middlewares/interceptor"
|
"github.com/goharbor/harbor/src/core/middlewares/interceptor"
|
||||||
"github.com/goharbor/harbor/src/core/middlewares/util"
|
"github.com/goharbor/harbor/src/core/middlewares/util"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type countQuotaHandler struct {
|
type countQuotaHandler struct {
|
||||||
@ -58,8 +58,8 @@ func (h *countQuotaHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
|
|||||||
|
|
||||||
if err := interceptor.HandleRequest(req); err != nil {
|
if err := interceptor.HandleRequest(req); err != nil {
|
||||||
log.Warningf("Error occurred when to handle request in count quota handler: %v", err)
|
log.Warningf("Error occurred when to handle request in count quota handler: %v", err)
|
||||||
if strings.Contains(err.Error(), "resource overflow the hard limit") {
|
if _, ok := err.(quota.Errors); ok {
|
||||||
http.Error(rw, util.MarshalError("DENIED", fmt.Sprintf("Not enough quota is available to process the request: %v", err)), http.StatusForbidden)
|
http.Error(rw, util.MarshalError("DENIED", fmt.Sprintf("Quota exceeded when processing the request of %v", err)), http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.Error(rw, util.MarshalError("InternalError", fmt.Sprintf("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 count quota handler: %v", err)),
|
||||||
|
@ -18,10 +18,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/common/quota"
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/core/middlewares/interceptor"
|
"github.com/goharbor/harbor/src/core/middlewares/interceptor"
|
||||||
"github.com/goharbor/harbor/src/core/middlewares/util"
|
"github.com/goharbor/harbor/src/core/middlewares/util"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type sizeQuotaHandler struct {
|
type sizeQuotaHandler struct {
|
||||||
@ -58,8 +58,8 @@ func (h *sizeQuotaHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
|
|||||||
|
|
||||||
if err := interceptor.HandleRequest(req); err != nil {
|
if err := interceptor.HandleRequest(req); err != nil {
|
||||||
log.Warningf("Error occurred when to handle request in size quota handler: %v", err)
|
log.Warningf("Error occurred when to handle request in size quota handler: %v", err)
|
||||||
if strings.Contains(err.Error(), "resource overflow the hard limit") {
|
if _, ok := err.(quota.Errors); ok {
|
||||||
http.Error(rw, util.MarshalError("DENIED", fmt.Sprintf("Not enough quota is available to process the request: %v", err)), http.StatusForbidden)
|
http.Error(rw, util.MarshalError("DENIED", fmt.Sprintf("Quota exceeded when processing the request of %v", err)), http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.Error(rw, util.MarshalError("InternalError", fmt.Sprintf("Error occurred when to handle request in size quota handler: %v", err)),
|
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