26 lines
981 B
Python
26 lines
981 B
Python
|
|
"""Shared auth-specific exceptions."""
|
||
|
|
|
||
|
|
from app.core.errors import AppError
|
||
|
|
|
||
|
|
_AUTH_CODE_MAP: dict[str, tuple[int, str]] = {
|
||
|
|
"INVALID_CREDENTIALS": (401, "AUTHENTICATION_FAILED"),
|
||
|
|
"INVALID_TOKEN": (401, "AUTHENTICATION_FAILED"),
|
||
|
|
"TOKEN_REVOKED": (401, "AUTHENTICATION_FAILED"),
|
||
|
|
"TOKEN_EXPIRED": (401, "AUTHENTICATION_FAILED"),
|
||
|
|
"REFRESH_TOKEN_REUSE": (401, "REFRESH_TOKEN_REUSE"),
|
||
|
|
"USER_NOT_FOUND": (404, "NOT_FOUND"),
|
||
|
|
"PHONE_EXISTS": (400, "PHONE_EXISTS"),
|
||
|
|
"EMAIL_EXISTS": (400, "EMAIL_EXISTS"),
|
||
|
|
"PHONE_TAKEN": (409, "PHONE_TAKEN"),
|
||
|
|
"INVALID_SMS_CODE": (400, "INVALID_SMS_CODE"),
|
||
|
|
"WRONG_PASSWORD": (400, "WRONG_PASSWORD"),
|
||
|
|
"AUTH_ERROR": (400, "BAD_REQUEST"),
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
class AuthError(AppError):
|
||
|
|
def __init__(self, message: str, code: str = "AUTH_ERROR"):
|
||
|
|
status_code, error_code = _AUTH_CODE_MAP.get(code, (400, code))
|
||
|
|
super().__init__(message, status_code=status_code, error_code=error_code)
|
||
|
|
self.code = code
|