"""Typed error definitions for auth plugin.""" from enum import StrEnum from pydantic import BaseModel class AuthErrorCode(StrEnum): INVALID_CREDENTIALS = "invalid_credentials" TOKEN_EXPIRED = "token_expired" TOKEN_INVALID = "token_invalid" USER_NOT_FOUND = "user_not_found" EMAIL_ALREADY_EXISTS = "email_already_exists" PROVIDER_NOT_FOUND = "provider_not_found" NOT_AUTHENTICATED = "not_authenticated" SYSTEM_ALREADY_INITIALIZED = "system_already_initialized" class TokenError(StrEnum): EXPIRED = "expired" INVALID_SIGNATURE = "invalid_signature" MALFORMED = "malformed" class AuthErrorResponse(BaseModel): code: AuthErrorCode message: str def token_error_to_code(err: TokenError) -> AuthErrorCode: if err == TokenError.EXPIRED: return AuthErrorCode.TOKEN_EXPIRED return AuthErrorCode.TOKEN_INVALID