mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 14:03:24 +09:00
enhance: Improve validation errors for secrets/variables (#39221)
Signed-off-by: Ross Golder <ross@golder.org> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
co-authored by
wxiaoguang
parent
ce2fd8d882
commit
2d3ad4a530
+4
-15
@@ -170,22 +170,11 @@ func (ctx *APIContext) APIError(status int, msg string) {
|
||||
|
||||
// APIErrorAuto use error check function to determine the response code
|
||||
func (ctx *APIContext) APIErrorAuto(err error) {
|
||||
switch {
|
||||
case errors.Is(err, util.ErrInvalidArgument):
|
||||
ctx.APIError(http.StatusBadRequest, err.Error())
|
||||
case errors.Is(err, util.ErrPermissionDenied):
|
||||
ctx.APIError(http.StatusForbidden, err.Error())
|
||||
case errors.Is(err, util.ErrNotExist):
|
||||
ctx.APIError(http.StatusNotFound, err.Error())
|
||||
case errors.Is(err, util.ErrAlreadyExist):
|
||||
ctx.APIError(http.StatusConflict, err.Error())
|
||||
case errors.Is(err, util.ErrContentTooLarge):
|
||||
ctx.APIError(http.StatusRequestEntityTooLarge, err.Error())
|
||||
case errors.Is(err, util.ErrUnprocessableContent):
|
||||
ctx.APIError(http.StatusUnprocessableEntity, err.Error())
|
||||
default:
|
||||
ctx.apiErrorInternal(1, err)
|
||||
if errMsg, code := util.ErrorUnwrapForUser(err); errMsg != "" {
|
||||
ctx.APIError(code, errMsg)
|
||||
return
|
||||
}
|
||||
ctx.apiErrorInternal(1, err)
|
||||
}
|
||||
|
||||
type apiContextKeyType struct{}
|
||||
|
||||
Reference in New Issue
Block a user