diff options
author | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-03-16 01:22:27 +0800 |
---|---|---|
committer | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-03-16 01:22:27 +0800 |
commit | 9e9ca66467116e9079a2639c00e9e623aca23015 (patch) | |
tree | dacdef5392608ff7107e4dd498959d4899e13e54 /internal/db/ssh_key.go | |
parent | 82ff0c5852f29daa5f95d965fd50665581e7ea3c (diff) |
refactor: unify error handling in routing layer
Diffstat (limited to 'internal/db/ssh_key.go')
-rw-r--r-- | internal/db/ssh_key.go | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/internal/db/ssh_key.go b/internal/db/ssh_key.go index b31c0da1..b82f81a6 100644 --- a/internal/db/ssh_key.go +++ b/internal/db/ssh_key.go @@ -24,6 +24,7 @@ import ( "xorm.io/xorm" "gogs.io/gogs/internal/conf" + "gogs.io/gogs/internal/errutil" "gogs.io/gogs/internal/process" ) @@ -684,6 +685,25 @@ func AddDeployKey(repoID int64, name, content string) (*DeployKey, error) { return key, sess.Commit() } +var _ errutil.NotFound = (*ErrDeployKeyNotExist)(nil) + +type ErrDeployKeyNotExist struct { + args map[string]interface{} +} + +func IsErrDeployKeyNotExist(err error) bool { + _, ok := err.(ErrDeployKeyNotExist) + return ok +} + +func (err ErrDeployKeyNotExist) Error() string { + return fmt.Sprintf("deploy key does not exist: %v", err.args) +} + +func (ErrDeployKeyNotExist) NotFound() bool { + return true +} + // GetDeployKeyByID returns deploy key by given ID. func GetDeployKeyByID(id int64) (*DeployKey, error) { key := new(DeployKey) @@ -691,7 +711,7 @@ func GetDeployKeyByID(id int64) (*DeployKey, error) { if err != nil { return nil, err } else if !has { - return nil, ErrDeployKeyNotExist{id, 0, 0} + return nil, ErrDeployKeyNotExist{args: map[string]interface{}{"deployKeyID": id}} } return key, nil } @@ -706,7 +726,7 @@ func GetDeployKeyByRepo(keyID, repoID int64) (*DeployKey, error) { if err != nil { return nil, err } else if !has { - return nil, ErrDeployKeyNotExist{0, keyID, repoID} + return nil, ErrDeployKeyNotExist{args: map[string]interface{}{"keyID": keyID, "repoID": repoID}} } return key, nil } |