aboutsummaryrefslogtreecommitdiff
path: root/internal/db
diff options
context:
space:
mode:
authorJoe Chen <jc@unknwon.io>2022-11-27 15:53:26 +0800
committerGitHub <noreply@github.com>2022-11-27 15:53:26 +0800
commit44333afd20a6312b617e0c33a497a4385ba3a250 (patch)
tree08550527657f6af16fab8d42b863cda4c34da095 /internal/db
parent13099a7e4fe7565bb858646d42d1fba817cb06cc (diff)
chore: consistently use `errors.Cause` for identifying error types (#7264)
Diffstat (limited to 'internal/db')
-rw-r--r--internal/db/access_tokens.go5
-rw-r--r--internal/db/email_addresses.go2
-rw-r--r--internal/db/users.go15
3 files changed, 19 insertions, 3 deletions
diff --git a/internal/db/access_tokens.go b/internal/db/access_tokens.go
index 58f77858..9dab65d4 100644
--- a/internal/db/access_tokens.go
+++ b/internal/db/access_tokens.go
@@ -9,6 +9,7 @@ import (
"fmt"
"time"
+ "github.com/pkg/errors"
gouuid "github.com/satori/go.uuid"
"gorm.io/gorm"
@@ -130,8 +131,10 @@ type ErrAccessTokenNotExist struct {
args errutil.Args
}
+// IsErrAccessTokenNotExist returns true if the underlying error has the type
+// ErrAccessTokenNotExist.
func IsErrAccessTokenNotExist(err error) bool {
- _, ok := err.(ErrAccessTokenNotExist)
+ _, ok := errors.Cause(err).(ErrAccessTokenNotExist)
return ok
}
diff --git a/internal/db/email_addresses.go b/internal/db/email_addresses.go
index 8cef705e..4f30a898 100644
--- a/internal/db/email_addresses.go
+++ b/internal/db/email_addresses.go
@@ -45,6 +45,8 @@ type ErrEmailNotExist struct {
args errutil.Args
}
+// IsErrEmailAddressNotExist returns true if the underlying error has the type
+// ErrEmailNotExist.
func IsErrEmailAddressNotExist(err error) bool {
_, ok := errors.Cause(err).(ErrEmailNotExist)
return ok
diff --git a/internal/db/users.go b/internal/db/users.go
index 2b599597..9e5687d4 100644
--- a/internal/db/users.go
+++ b/internal/db/users.go
@@ -112,6 +112,13 @@ type ErrLoginSourceMismatch struct {
args errutil.Args
}
+// IsErrLoginSourceMismatch returns true if the underlying error has the type
+// ErrLoginSourceMismatch.
+func IsErrLoginSourceMismatch(err error) bool {
+ _, ok := errors.Cause(err).(ErrLoginSourceMismatch)
+ return ok
+}
+
func (err ErrLoginSourceMismatch) Error() string {
return fmt.Sprintf("login source mismatch: %v", err.args)
}
@@ -302,8 +309,10 @@ type ErrUserAlreadyExist struct {
args errutil.Args
}
+// IsErrUserAlreadyExist returns true if the underlying error has the type
+// ErrUserAlreadyExist.
func IsErrUserAlreadyExist(err error) bool {
- _, ok := err.(ErrUserAlreadyExist)
+ _, ok := errors.Cause(err).(ErrUserAlreadyExist)
return ok
}
@@ -879,8 +888,10 @@ type ErrNameNotAllowed struct {
args errutil.Args
}
+// IsErrNameNotAllowed returns true if the underlying error has the type
+// ErrNameNotAllowed.
func IsErrNameNotAllowed(err error) bool {
- _, ok := err.(ErrNameNotAllowed)
+ _, ok := errors.Cause(err).(ErrNameNotAllowed)
return ok
}