98 lines
3.9 KiB
Go
98 lines
3.9 KiB
Go
package errors
|
|
|
|
import "errors"
|
|
|
|
var (
|
|
ErrNotFound = errors.New("not found")
|
|
ErrUserNotFound = errors.New("user not found")
|
|
ErrInvalidEmail = errors.New("invalid email")
|
|
ErrInvalidCredentials = errors.New("invalid credentials: unauthorized")
|
|
ErrAlreadyVerified = errors.New("user is already verified")
|
|
ErrTokenNotFound = errors.New("verification token not found")
|
|
ErrTokenNotSet = errors.New("verification token has not been set")
|
|
ErrNoData = errors.New("no data provided")
|
|
ErrNoRowsAffected = errors.New("no rows affected")
|
|
ErrValueTooLong = errors.New("cookie value too long")
|
|
ErrInvalidValue = errors.New("invalid cookie value")
|
|
ErrInvalidSigningAlgorithm = errors.New("invalid signing algorithm")
|
|
ErrValidToken = errors.New("valid token")
|
|
ErrInvalidUserData = errors.New("invalid user data")
|
|
ErrDuplicateEntry = errors.New("duplicate entry; unique constraint failed")
|
|
ErrNotAuthorized = errors.New("not authorized")
|
|
ValErrParentIDNotSet = errors.New("Parent Membership ID not provided")
|
|
ValErrParentIDNotFound = errors.New("Parent Membership ID not found")
|
|
ErrSubscriptionNotFound = errors.New("Subscription Model not found")
|
|
ErrSubscriptionInUse = errors.New("This subscription is in active use by existing members.")
|
|
ErrInvalidSubscriptionData = errors.New("Provided subscription data is invalid. Immutable fields where changed.")
|
|
)
|
|
|
|
type ValidationKeys struct {
|
|
Invalid string
|
|
InternalServerError string
|
|
InvalidJSON string
|
|
InvalidUserID string
|
|
InvalidSubscription string
|
|
Unauthorized string
|
|
UserNotFoundWrongPassword string
|
|
JwtGenerationFailed string
|
|
Duplicate string
|
|
UserDisabled string
|
|
PasswordAlreadyChanged string
|
|
NoAuthToken string
|
|
NotFound string
|
|
InUse string
|
|
UndeliveredVerificationMail string
|
|
UserAlreadyVerified string
|
|
}
|
|
|
|
type ValidationFields struct {
|
|
General string
|
|
ParentMembershipID string
|
|
Subscription string
|
|
Login string
|
|
Email string
|
|
User string
|
|
Licences string
|
|
Verification string
|
|
Car string
|
|
}
|
|
|
|
var Responses = struct {
|
|
Keys ValidationKeys
|
|
Fields ValidationFields
|
|
}{
|
|
Keys: ValidationKeys{
|
|
Invalid: "server.validation.invalid",
|
|
InternalServerError: "server.error.internal_server_error",
|
|
InvalidJSON: "server.error.invalid_json",
|
|
InvalidUserID: "server.validation.invalid_user_id",
|
|
InvalidSubscription: "server.validation.invalid_subscription",
|
|
Unauthorized: "server.error.unauthorized",
|
|
UserNotFoundWrongPassword: "server.validation.user_not_found_or_wrong_password",
|
|
JwtGenerationFailed: "server.error.jwt_generation_failed",
|
|
Duplicate: "server.validation.duplicate",
|
|
UserDisabled: "server.validation.user_disabled",
|
|
PasswordAlreadyChanged: "server.validation.password_already_changed",
|
|
NoAuthToken: "server.error.no_auth_token",
|
|
NotFound: "server.error.not_found",
|
|
InUse: "server.error.in_use",
|
|
UndeliveredVerificationMail: "server.error.undelivered_verification_mail",
|
|
UserAlreadyVerified: "server.validation.user_already_verified",
|
|
},
|
|
Fields: ValidationFields{
|
|
General: "server.general",
|
|
ParentMembershipID: "parent_membership_id",
|
|
Subscription: "subscription",
|
|
Login: "user.login",
|
|
Email: "user.email",
|
|
User: "user.user",
|
|
Licences: "licence",
|
|
Verification: "verification",
|
|
Car: "car",
|
|
},
|
|
}
|
|
|
|
func Is(err error, target error) bool {
|
|
return errors.Is(err, target)
|
|
}
|