Skip to content

Commit

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

Backport go-gitea#24823 by @sonjek

Should resolve first point of the issue
go-gitea#24574

Co-authored-by: Yevhen Pavlov <yevhen.pavlov.ua@gmail.com>
(cherry picked from commit f29c52a)
  • Loading branch information
GiteaBot authored and earl-warren committed May 23, 2023
1 parent 5dc29fd commit 16bccee
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 @@ -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)
Expand Down

0 comments on commit 16bccee

Please sign in to comment.