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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
184 changed files with 2100 additions and 2106 deletions

View file

@ -46,13 +46,13 @@ func ListLabels(ctx *context.APIContext) {
labels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsByOrgID", err)
ctx.APIError(http.StatusInternalServerError, err)
return
}
count, err := issues_model.CountLabelsByOrgID(ctx, ctx.Org.Organization.ID)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
@ -90,7 +90,7 @@ func CreateLabel(ctx *context.APIContext) {
form.Color = strings.Trim(form.Color, " ")
color, err := label.NormalizeColor(form.Color)
if err != nil {
ctx.Error(http.StatusUnprocessableEntity, "Color", err)
ctx.APIError(http.StatusUnprocessableEntity, err)
return
}
form.Color = color
@ -103,7 +103,7 @@ func CreateLabel(ctx *context.APIContext) {
Description: form.Description,
}
if err := issues_model.NewLabel(ctx, label); err != nil {
ctx.Error(http.StatusInternalServerError, "NewLabel", err)
ctx.APIError(http.StatusInternalServerError, err)
return
}
@ -147,9 +147,9 @@ func GetLabel(ctx *context.APIContext) {
}
if err != nil {
if issues_model.IsErrOrgLabelNotExist(err) {
ctx.NotFound()
ctx.APIErrorNotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetLabelByOrgID", err)
ctx.APIError(http.StatusInternalServerError, err)
}
return
}
@ -193,9 +193,9 @@ func EditLabel(ctx *context.APIContext) {
l, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id"))
if err != nil {
if issues_model.IsErrOrgLabelNotExist(err) {
ctx.NotFound()
ctx.APIErrorNotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetLabelByRepoID", err)
ctx.APIError(http.StatusInternalServerError, err)
}
return
}
@ -209,7 +209,7 @@ func EditLabel(ctx *context.APIContext) {
if form.Color != nil {
color, err := label.NormalizeColor(*form.Color)
if err != nil {
ctx.Error(http.StatusUnprocessableEntity, "Color", err)
ctx.APIError(http.StatusUnprocessableEntity, err)
return
}
l.Color = color
@ -219,7 +219,7 @@ func EditLabel(ctx *context.APIContext) {
}
l.SetArchived(form.IsArchived != nil && *form.IsArchived)
if err := issues_model.UpdateLabel(ctx, l); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateLabel", err)
ctx.APIError(http.StatusInternalServerError, err)
return
}
@ -250,7 +250,7 @@ func DeleteLabel(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
if err := issues_model.DeleteLabel(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id")); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteLabel", err)
ctx.APIError(http.StatusInternalServerError, err)
return
}