1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 02:38:35 +00:00

Refactor error system (#33610)

This commit is contained in:
wxiaoguang
2025-02-17 14:13:17 +08:00
committed by GitHub
parent 69de5a65c2
commit f35850f48e
184 changed files with 2100 additions and 2106 deletions

View File

@@ -48,7 +48,7 @@ func GetGitignoreTemplateInfo(ctx *context.APIContext) {
text, err := options.Gitignore(name)
if err != nil {
ctx.NotFound()
ctx.APIErrorNotFound()
return
}

View File

@@ -52,7 +52,7 @@ func GetLabelTemplate(ctx *context.APIContext) {
labels, err := repo_module.LoadTemplateLabelsByDisplayName(name)
if err != nil {
ctx.NotFound()
ctx.APIErrorNotFound()
return
}

View File

@@ -59,7 +59,7 @@ func GetLicenseTemplateInfo(ctx *context.APIContext) {
text, err := options.License(name)
if err != nil {
ctx.NotFound()
ctx.APIErrorNotFound()
return
}

View File

@@ -38,7 +38,7 @@ func Markup(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.MarkupOption)
if ctx.HasAPIError() {
ctx.Error(http.StatusUnprocessableEntity, "", ctx.GetErrMsg())
ctx.APIError(http.StatusUnprocessableEntity, ctx.GetErrMsg())
return
}
@@ -69,7 +69,7 @@ func Markdown(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.MarkdownOption)
if ctx.HasAPIError() {
ctx.Error(http.StatusUnprocessableEntity, "", ctx.GetErrMsg())
ctx.APIError(http.StatusUnprocessableEntity, ctx.GetErrMsg())
return
}
@@ -100,7 +100,7 @@ func MarkdownRaw(ctx *context.APIContext) {
// "$ref": "#/responses/validationError"
defer ctx.Req.Body.Close()
if err := markdown.RenderRaw(markup.NewRenderContext(ctx), ctx.Req.Body, ctx.Resp); err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
}

View File

@@ -52,7 +52,7 @@ func NodeInfo(ctx *context.APIContext) {
}
if err := ctx.Cache.PutJSON(cacheKeyNodeInfoUsage, nodeInfoUsage, 180); err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
}

View File

@@ -53,11 +53,11 @@ func SigningKey(ctx *context.APIContext) {
content, err := asymkey_service.PublicSigningKey(ctx, path)
if err != nil {
ctx.Error(http.StatusInternalServerError, "gpg export", err)
ctx.APIError(http.StatusInternalServerError, err)
return
}
_, err = ctx.Write([]byte(content))
if err != nil {
ctx.Error(http.StatusInternalServerError, "gpg export", fmt.Errorf("Error writing key content %w", err))
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("Error writing key content %w", err))
}
}