aboutsummaryrefslogtreecommitdiff
path: root/internal/db/webhook.go
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-03-16 01:22:27 +0800
committerᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-03-16 01:22:27 +0800
commit9e9ca66467116e9079a2639c00e9e623aca23015 (patch)
treedacdef5392608ff7107e4dd498959d4899e13e54 /internal/db/webhook.go
parent82ff0c5852f29daa5f95d965fd50665581e7ea3c (diff)
refactor: unify error handling in routing layer
Diffstat (limited to 'internal/db/webhook.go')
-rw-r--r--internal/db/webhook.go44
1 files changed, 41 insertions, 3 deletions
diff --git a/internal/db/webhook.go b/internal/db/webhook.go
index 418f2729..1547a276 100644
--- a/internal/db/webhook.go
+++ b/internal/db/webhook.go
@@ -22,7 +22,7 @@ import (
api "github.com/gogs/go-gogs-client"
"gogs.io/gogs/internal/conf"
- "gogs.io/gogs/internal/db/errors"
+ "gogs.io/gogs/internal/errutil"
"gogs.io/gogs/internal/httplib"
"gogs.io/gogs/internal/sync"
)
@@ -235,6 +235,25 @@ func CreateWebhook(w *Webhook) error {
return err
}
+var _ errutil.NotFound = (*ErrWebhookNotExist)(nil)
+
+type ErrWebhookNotExist struct {
+ args map[string]interface{}
+}
+
+func IsErrWebhookNotExist(err error) bool {
+ _, ok := err.(ErrWebhookNotExist)
+ return ok
+}
+
+func (err ErrWebhookNotExist) Error() string {
+ return fmt.Sprintf("webhook does not exist: %v", err.args)
+}
+
+func (ErrWebhookNotExist) NotFound() bool {
+ return true
+}
+
// getWebhook uses argument bean as query condition,
// ID must be specified and do not assign unnecessary fields.
func getWebhook(bean *Webhook) (*Webhook, error) {
@@ -242,7 +261,7 @@ func getWebhook(bean *Webhook) (*Webhook, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.WebhookNotExist{ID: bean.ID}
+ return nil, ErrWebhookNotExist{args: map[string]interface{}{"webhookID": bean.ID}}
}
return bean, nil
}
@@ -499,6 +518,25 @@ func createHookTask(e Engine, t *HookTask) error {
return err
}
+var _ errutil.NotFound = (*ErrHookTaskNotExist)(nil)
+
+type ErrHookTaskNotExist struct {
+ args map[string]interface{}
+}
+
+func IsHookTaskNotExist(err error) bool {
+ _, ok := err.(ErrHookTaskNotExist)
+ return ok
+}
+
+func (err ErrHookTaskNotExist) Error() string {
+ return fmt.Sprintf("hook task does not exist: %v", err.args)
+}
+
+func (ErrHookTaskNotExist) NotFound() bool {
+ return true
+}
+
// GetHookTaskOfWebhookByUUID returns hook task of given webhook by UUID.
func GetHookTaskOfWebhookByUUID(webhookID int64, uuid string) (*HookTask, error) {
hookTask := &HookTask{
@@ -509,7 +547,7 @@ func GetHookTaskOfWebhookByUUID(webhookID int64, uuid string) (*HookTask, error)
if err != nil {
return nil, err
} else if !has {
- return nil, errors.HookTaskNotExist{HookID: webhookID, UUID: uuid}
+ return nil, ErrHookTaskNotExist{args: map[string]interface{}{"webhookID": webhookID, "uuid": uuid}}
}
return hookTask, nil
}