58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package usecase
|
|
|
|
import "errors"
|
|
|
|
const (
|
|
ErrorKindUnauthorized ErrorKind = "UNAUTHORIZED"
|
|
ErrorKindForbidden ErrorKind = "FORBIDDEN"
|
|
)
|
|
|
|
func wrapAuthRepositoryError(err error) error {
|
|
switch {
|
|
case errors.Is(err, ErrAuthCredentials):
|
|
return newError(
|
|
ErrorKindUnauthorized,
|
|
"AUTH_INVALID_CREDENTIALS",
|
|
"invalid credentials",
|
|
err,
|
|
)
|
|
case errors.Is(err, ErrAuthDisabled):
|
|
return newError(
|
|
ErrorKindForbidden,
|
|
"AUTH_ACCOUNT_OR_DEVICE_DISABLED",
|
|
"account or device is disabled",
|
|
err,
|
|
)
|
|
case errors.Is(err, ErrAuthForbidden):
|
|
return newError(
|
|
ErrorKindForbidden,
|
|
"AUTH_FORBIDDEN",
|
|
"identity is not allowed to perform this operation",
|
|
err,
|
|
)
|
|
case errors.Is(err, ErrAuthExpired):
|
|
return newError(
|
|
ErrorKindUnauthorized,
|
|
"AUTH_SESSION_EXPIRED",
|
|
"session expired",
|
|
err,
|
|
)
|
|
case errors.Is(err, ErrAuthRevoked):
|
|
return newError(
|
|
ErrorKindUnauthorized,
|
|
"AUTH_INVALID_TOKEN",
|
|
"invalid token",
|
|
err,
|
|
)
|
|
case errors.Is(err, ErrAuthConflict):
|
|
return newError(
|
|
ErrorKindConflict,
|
|
"AUTH_RESOURCE_CONFLICT",
|
|
"authentication resource already exists",
|
|
err,
|
|
)
|
|
default:
|
|
return wrapRepositoryError(err)
|
|
}
|
|
}
|