diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index c32a98d0c5..bccde18df6 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -97,14 +97,12 @@ func CreateUser(ctx *context.APIContext) { if u.LoginType == auth.Plain { if len(form.Password) < setting.MinPasswordLength { - err := errors.New("PasswordIsRequired") - ctx.APIError(http.StatusBadRequest, err.Error()) + ctx.APIError(http.StatusBadRequest, "PasswordIsRequired") return } if !password.IsComplexEnough(form.Password) { - err := errors.New("PasswordComplexity") - ctx.APIError(http.StatusBadRequest, err.Error()) + ctx.APIError(http.StatusBadRequest, "PasswordComplexity") return } diff --git a/routers/api/v1/org/action.go b/routers/api/v1/org/action.go index fb1277a5f4..3f1135dcf3 100644 --- a/routers/api/v1/org/action.go +++ b/routers/api/v1/org/action.go @@ -387,7 +387,7 @@ func (Action) CreateVariable(ctx *context.APIContext) { return } if v != nil && v.ID > 0 { - ctx.APIError(http.StatusConflict, util.NewAlreadyExistErrorf("variable name %s already exists", variableName).Error()) + ctx.APIError(http.StatusConflict, "variable name already exists") return } diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index cfb9f8bf5f..5fc2e97d7a 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -361,7 +361,7 @@ func (Action) CreateVariable(ctx *context.APIContext) { return } if v != nil && v.ID > 0 { - ctx.APIError(http.StatusConflict, util.NewAlreadyExistErrorf("variable name %s already exists", variableName).Error()) + ctx.APIError(http.StatusConflict, "variable name already exists") return } @@ -1062,7 +1062,7 @@ func ActionsDispatchWorkflow(ctx *context.APIContext) { workflowID := ctx.PathParam("workflow_id") opt := web.GetForm(ctx).(*api.CreateActionWorkflowDispatch) if opt.Ref == "" { - ctx.APIError(http.StatusUnprocessableEntity, util.NewInvalidArgumentErrorf("ref is required parameter").Error()) + ctx.APIError(http.StatusUnprocessableEntity, "ref is required parameter") return } @@ -1560,7 +1560,7 @@ func ListWorkflowRunJobs(ctx *context.APIContext) { // Avoid the list all jobs functionality for this api route to be used with a runID == 0. if runID <= 0 { - ctx.APIError(http.StatusBadRequest, util.NewInvalidArgumentErrorf("runID must be a positive integer").Error()) + ctx.APIError(http.StatusBadRequest, "runID must be a positive integer") return } diff --git a/routers/api/v1/repo/mirror.go b/routers/api/v1/repo/mirror.go index 6f72c9613c..c76946493a 100644 --- a/routers/api/v1/repo/mirror.go +++ b/routers/api/v1/repo/mirror.go @@ -5,6 +5,7 @@ package repo import ( "errors" + "fmt" "net/http" "strings" "time" @@ -344,8 +345,12 @@ func CreatePushMirror(ctx *context.APIContext, mirrorOption *api.CreatePushMirro repo := ctx.Repo.Repository interval, err := time.ParseDuration(mirrorOption.Interval) - if err != nil || (interval != 0 && interval < setting.Mirror.MinInterval) { - ctx.APIError(http.StatusBadRequest, err.Error()) + if err != nil { + ctx.APIError(http.StatusBadRequest, fmt.Sprintf("invalid interval: %v", err)) + return + } + if interval != 0 && interval < setting.Mirror.MinInterval { + ctx.APIError(http.StatusBadRequest, fmt.Sprintf("interval is shorter than minimum %v", setting.Mirror.MinInterval.String())) return } diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index d199a77ba5..a4fc03ae32 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -4,7 +4,6 @@ package repo import ( - "fmt" "net/http" auth_model "gitea.dev/models/auth" @@ -276,7 +275,7 @@ func CreateRelease(ctx *context.APIContext) { } else if release_service.IsErrProtectedTagName(err) { ctx.APIError(http.StatusUnprocessableEntity, err.Error()) } else if git.IsErrNotExist(err) { - ctx.APIError(http.StatusNotFound, fmt.Sprintf("target \"%v\" not found: %v", rel.Target, err)) + ctx.APIError(http.StatusNotFound, "target not found") } else { ctx.APIErrorInternal(err) } diff --git a/routers/api/v1/user/action.go b/routers/api/v1/user/action.go index 08abe85ac8..1086b22192 100644 --- a/routers/api/v1/user/action.go +++ b/routers/api/v1/user/action.go @@ -148,7 +148,7 @@ func CreateVariable(ctx *context.APIContext) { return } if v != nil && v.ID > 0 { - ctx.APIError(http.StatusConflict, util.NewAlreadyExistErrorf("variable name %s already exists", variableName).Error()) + ctx.APIError(http.StatusConflict, "variable name already exists") return }