Skip to content

Commit 1dfaf83

Browse files
authored
Return 404 in the API if the requested webhooks were not found (#24823)
Should resolve first point of the issue #24574
1 parent 6b33152 commit 1dfaf83

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)
@@ -160,7 +165,7 @@ func DeleteHook(ctx *context.APIContext) {
160165

161166
hookID := ctx.ParamsInt64(":id")
162167
if err := webhook.DeleteDefaultSystemWebhook(ctx, hookID); err != nil {
163-
if webhook.IsErrWebhookNotExist(err) {
168+
if errors.Is(err, util.ErrNotExist) {
164169
ctx.NotFound()
165170
} else {
166171
ctx.Error(http.StatusInternalServerError, "DeleteDefaultSystemWebhook", err)

0 commit comments

Comments
 (0)