1
1
Fork 1
mirror of https://github.com/go-gitea/gitea.git synced 2024-05-26 09:46:12 +02:00

Return `404` in the API if the requested webhooks were not found (#24823)

Should resolve first point of the issue
https://github.com/go-gitea/gitea/issues/24574
This commit is contained in:
Yevhen Pavlov 2023-05-21 05:54:28 +03:00 committed by GitHub
parent 6b33152b7d
commit 1dfaf83798
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
@ -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)