Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 21 additions & 0 deletions tests/integration/api_admin_hook_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package integration

import (
"net/http"
"net/url"
"testing"

"code.gitea.io/gitea/tests"
)

func TestGetNotExistHook(t *testing.T) {
onGiteaRun(t, func(*testing.T, *url.URL) {
defer tests.PrepareTestEnv(t)()

req := NewRequest(t, "GET", "/api/v1/admin/hooks/1234")
MakeRequest(t, req, http.StatusNotFound)
})
}