Skip to content

Commit f29c52a

Browse files
GiteaBotsonjek
andauthored
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 #24574 Co-authored-by: Yevhen Pavlov <yevhen.pavlov.ua@gmail.com>
1 parent 04f9ab1 commit f29c52a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

routers/api/v1/admin/hooks.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package admin
55

66
import (
7+
"errors"
78
"net/http"
89

910
"code.gitea.io/gitea/models/webhook"
@@ -74,7 +75,11 @@ func GetHook(ctx *context.APIContext) {
7475
hookID := ctx.ParamsInt64(":id")
7576
hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
7677
if err != nil {
77-
ctx.Error(http.StatusInternalServerError, "GetSystemOrDefaultWebhook", err)
78+
if errors.Is(err, util.ErrNotExist) {
79+
ctx.NotFound()
80+
} else {
81+
ctx.Error(http.StatusInternalServerError, "GetSystemOrDefaultWebhook", err)
82+
}
7883
return
7984
}
8085
h, err := webhook_service.ToHook("/admin/", hook)
@@ -163,7 +168,7 @@ func DeleteHook(ctx *context.APIContext) {
163168

164169
hookID := ctx.ParamsInt64(":id")
165170
if err := webhook.DeleteDefaultSystemWebhook(ctx, hookID); err != nil {
166-
if webhook.IsErrWebhookNotExist(err) {
171+
if errors.Is(err, util.ErrNotExist) {
167172
ctx.NotFound()
168173
} else {
169174
ctx.Error(http.StatusInternalServerError, "DeleteDefaultSystemWebhook", err)

0 commit comments

Comments
 (0)