summaryrefslogtreecommitdiffstats
path: root/models/error.go
diff options
context:
space:
mode:
authorAntoine GIRARD <sapk@users.noreply.github.com>2017-03-16 02:27:35 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2017-03-16 09:27:35 +0800
commitca1c3f1926eff992a2458f26cb24ed2f35265b05 (patch)
treea0c859357539aebf4c3ce521fc8b5d1e6a870364 /models/error.go
parent43c5469f81851c084fa6ac84d8379ae949c3a05c (diff)
downloadgitea-ca1c3f1926eff992a2458f26cb24ed2f35265b05.tar.gz
gitea-ca1c3f1926eff992a2458f26cb24ed2f35265b05.zip
Implement GPG api (#710)
* Implement GPG API * Better handle error * Apply review recommendation + simplify database operations * Remove useless comments
Diffstat (limited to 'models/error.go')
-rw-r--r--models/error.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/models/error.go b/models/error.go
index 472c8c9426..62529f83fa 100644
--- a/models/error.go
+++ b/models/error.go
@@ -245,6 +245,54 @@ func (err ErrKeyNameAlreadyUsed) Error() string {
return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
}
+// ErrGPGKeyNotExist represents a "GPGKeyNotExist" kind of error.
+type ErrGPGKeyNotExist struct {
+ ID int64
+}
+
+// IsErrGPGKeyNotExist checks if an error is a ErrGPGKeyNotExist.
+func IsErrGPGKeyNotExist(err error) bool {
+ _, ok := err.(ErrGPGKeyNotExist)
+ return ok
+}
+
+func (err ErrGPGKeyNotExist) Error() string {
+ return fmt.Sprintf("public gpg key does not exist [id: %d]", err.ID)
+}
+
+// ErrGPGKeyIDAlreadyUsed represents a "GPGKeyIDAlreadyUsed" kind of error.
+type ErrGPGKeyIDAlreadyUsed struct {
+ KeyID string
+}
+
+// IsErrGPGKeyIDAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
+func IsErrGPGKeyIDAlreadyUsed(err error) bool {
+ _, ok := err.(ErrGPGKeyIDAlreadyUsed)
+ return ok
+}
+
+func (err ErrGPGKeyIDAlreadyUsed) Error() string {
+ return fmt.Sprintf("public key already exists [key_id: %s]", err.KeyID)
+}
+
+// ErrGPGKeyAccessDenied represents a "GPGKeyAccessDenied" kind of Error.
+type ErrGPGKeyAccessDenied struct {
+ UserID int64
+ KeyID int64
+}
+
+// IsErrGPGKeyAccessDenied checks if an error is a ErrGPGKeyAccessDenied.
+func IsErrGPGKeyAccessDenied(err error) bool {
+ _, ok := err.(ErrGPGKeyAccessDenied)
+ return ok
+}
+
+// Error pretty-prints an error of type ErrGPGKeyAccessDenied.
+func (err ErrGPGKeyAccessDenied) Error() string {
+ return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d]",
+ err.UserID, err.KeyID)
+}
+
// ErrKeyAccessDenied represents a "KeyAccessDenied" kind of error.
type ErrKeyAccessDenied struct {
UserID int64