aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/admin/hooks.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api/v1/admin/hooks.go')
-rw-r--r--routers/api/v1/admin/hooks.go19
1 files changed, 10 insertions, 9 deletions
diff --git a/routers/api/v1/admin/hooks.go b/routers/api/v1/admin/hooks.go
index c812ca182d..a687541be5 100644
--- a/routers/api/v1/admin/hooks.go
+++ b/routers/api/v1/admin/hooks.go
@@ -51,22 +51,23 @@ func ListHooks(ctx *context.APIContext) {
// for compatibility the default value is true
isSystemWebhook := optional.Some(true)
typeValue := ctx.FormString("type")
- if typeValue == "default" {
+ switch typeValue {
+ case "default":
isSystemWebhook = optional.Some(false)
- } else if typeValue == "all" {
+ case "all":
isSystemWebhook = optional.None[bool]()
}
sysHooks, err := webhook.GetSystemOrDefaultWebhooks(ctx, isSystemWebhook)
if err != nil {
- ctx.Error(http.StatusInternalServerError, "GetSystemWebhooks", err)
+ ctx.APIErrorInternal(err)
return
}
hooks := make([]*api.Hook, len(sysHooks))
for i, hook := range sysHooks {
h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", hook)
if err != nil {
- ctx.Error(http.StatusInternalServerError, "convert.ToHook", err)
+ ctx.APIErrorInternal(err)
return
}
hooks[i] = h
@@ -96,15 +97,15 @@ func GetHook(ctx *context.APIContext) {
hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
if err != nil {
if errors.Is(err, util.ErrNotExist) {
- ctx.NotFound()
+ ctx.APIErrorNotFound()
} else {
- ctx.Error(http.StatusInternalServerError, "GetSystemOrDefaultWebhook", err)
+ ctx.APIErrorInternal(err)
}
return
}
h, err := webhook_service.ToHook("/-/admin/", hook)
if err != nil {
- ctx.Error(http.StatusInternalServerError, "convert.ToHook", err)
+ ctx.APIErrorInternal(err)
return
}
ctx.JSON(http.StatusOK, h)
@@ -186,9 +187,9 @@ func DeleteHook(ctx *context.APIContext) {
hookID := ctx.PathParamInt64("id")
if err := webhook.DeleteDefaultSystemWebhook(ctx, hookID); err != nil {
if errors.Is(err, util.ErrNotExist) {
- ctx.NotFound()
+ ctx.APIErrorNotFound()
} else {
- ctx.Error(http.StatusInternalServerError, "DeleteDefaultSystemWebhook", err)
+ ctx.APIErrorInternal(err)
}
return
}