Skip to content

Commit

Permalink
Return 404 in the API if the requested webhooks were not found (#24823
Browse files Browse the repository at this point in the history
)

Should resolve first point of the issue
#24574
  • Loading branch information
sonjek committed May 21, 2023
1 parent 6b33152 commit 1dfaf83
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions routers/api/v1/admin/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package admin

import (
"errors"
"net/http"

"code.gitea.io/gitea/models/webhook"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -160,7 +165,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)
Expand Down

0 comments on commit 1dfaf83

Please sign in to comment.