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

@ -59,14 +59,14 @@ func ListHooks(ctx *context.APIContext) {
sysHooks, err := webhook.GetSystemOrDefaultWebhooks(ctx, isSystemWebhook)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetSystemWebhooks", err)
ctx.APIError(http.StatusInternalServerError, err)
return
}
hooks := make([]*api.Hook, len(sysHooks))
for i, hook := range sysHooks {
h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", hook)
if err != nil {
ctx.Error(http.StatusInternalServerError, "convert.ToHook", err)
ctx.APIError(http.StatusInternalServerError, err)
return
}
hooks[i] = h
@ -96,15 +96,15 @@ func GetHook(ctx *context.APIContext) {
hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
if err != nil {
if errors.Is(err, util.ErrNotExist) {
ctx.NotFound()
ctx.APIErrorNotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetSystemOrDefaultWebhook", err)
ctx.APIError(http.StatusInternalServerError, err)
}
return
}
h, err := webhook_service.ToHook("/-/admin/", hook)
if err != nil {
ctx.Error(http.StatusInternalServerError, "convert.ToHook", err)
ctx.APIError(http.StatusInternalServerError, err)
return
}
ctx.JSON(http.StatusOK, h)
@ -186,9 +186,9 @@ func DeleteHook(ctx *context.APIContext) {
hookID := ctx.PathParamInt64("id")
if err := webhook.DeleteDefaultSystemWebhook(ctx, hookID); err != nil {
if errors.Is(err, util.ErrNotExist) {
ctx.NotFound()
ctx.APIErrorNotFound()
} else {
ctx.Error(http.StatusInternalServerError, "DeleteDefaultSystemWebhook", err)
ctx.APIError(http.StatusInternalServerError, err)
}
return
}