From 16bcceeff7aa102de95bba6eb1caec27157e3623 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Sun, 21 May 2023 14:05:58 -0400 Subject: [PATCH] Return `404` in the API if the requested webhooks were not found (#24823) (#24830) Backport #24823 by @sonjek Should resolve first point of the issue https://github.com/go-gitea/gitea/issues/24574 Co-authored-by: Yevhen Pavlov (cherry picked from commit f29c52a1691656531db44404ba59d27bd0a1760a) --- routers/api/v1/admin/hooks.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/admin/hooks.go b/routers/api/v1/admin/hooks.go index d5603dd068..4a1840b789 100644 --- a/routers/api/v1/admin/hooks.go +++ b/routers/api/v1/admin/hooks.go @@ -4,6 +4,7 @@ package admin import ( + "errors" "net/http" "code.gitea.io/gitea/models/webhook" @@ -74,7 +75,11 @@ func GetHook(ctx *context.APIContext) { hookID := ctx.ParamsInt64(":id") hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetSystemOrDefaultWebhook", err) + if errors.Is(err, util.ErrNotExist) { + ctx.NotFound() + } else { + ctx.Error(http.StatusInternalServerError, "GetSystemOrDefaultWebhook", err) + } return } h, err := webhook_service.ToHook("/admin/", hook) @@ -163,7 +168,7 @@ func DeleteHook(ctx *context.APIContext) { hookID := ctx.ParamsInt64(":id") if err := webhook.DeleteDefaultSystemWebhook(ctx, hookID); err != nil { - if webhook.IsErrWebhookNotExist(err) { + if errors.Is(err, util.ErrNotExist) { ctx.NotFound() } else { ctx.Error(http.StatusInternalServerError, "DeleteDefaultSystemWebhook", err)