refactor(api): clarify APIError message usage and fix legacy lint error (#38012)

Avoid unclear & fragile "any" tricks, fix various abuses

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Copilot
2026-06-07 06:19:39 +00:00
committed by GitHub
co-authored by wxiaoguang
parent c43eb7c33a
commit 5fe4f962e8
64 changed files with 395 additions and 384 deletions
+4 -6
View File
@@ -4,8 +4,6 @@
package repo
import (
"errors"
"fmt"
"net/http"
auth_model "gitea.dev/models/auth"
@@ -243,7 +241,7 @@ func CreateRelease(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.CreateReleaseOption)
if ctx.Repo.Repository.IsEmpty {
ctx.APIError(http.StatusUnprocessableEntity, errors.New("repo is empty"))
ctx.APIError(http.StatusUnprocessableEntity, "repo is empty")
return
}
rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, form.TagName)
@@ -273,11 +271,11 @@ func CreateRelease(ctx *context.APIContext) {
// It doesn't need to be the same as the "release note"
if err := release_service.CreateRelease(ctx.Repo.GitRepo, rel, nil, form.TagMessage); err != nil {
if repo_model.IsErrReleaseAlreadyExist(err) {
ctx.APIError(http.StatusConflict, err)
ctx.APIError(http.StatusConflict, err.Error())
} else if release_service.IsErrProtectedTagName(err) {
ctx.APIError(http.StatusUnprocessableEntity, err)
ctx.APIError(http.StatusUnprocessableEntity, err.Error())
} else if git.IsErrNotExist(err) {
ctx.APIError(http.StatusNotFound, fmt.Errorf("target \"%v\" not found: %w", rel.Target, err))
ctx.APIError(http.StatusNotFound, "target not found")
} else {
ctx.APIErrorInternal(err)
}