Skip to content

Exceptions

The HTTP exceptions CRUDAuth raises. All subclass CustomException, which is a FastAPI HTTPException, so they propagate with the right status code and headers.

crudauth.exceptions.CustomException

CustomException(
    status_code: int = HTTP_500_INTERNAL_SERVER_ERROR,
    detail: Any = None,
    headers: dict[str, str] | None = None,
)

Bases: HTTPException

crudauth.exceptions.BadRequestException

BadRequestException(detail: str | None = None)

crudauth.exceptions.OAuthAccountException

OAuthAccountException(code: str, detail: str)

Bases: BadRequestException

A 400 refusing an OAuth sign-in while resolving the account.

code is the machine-readable reason the OAuth callback reports as error (email_missing, email_unverified, email_too_long, provider_already_linked); detail is the human-readable message.

crudauth.exceptions.NotFoundException

NotFoundException(detail: str | None = None)

crudauth.exceptions.ForbiddenException

ForbiddenException(detail: str | None = None)

crudauth.exceptions.UnauthorizedException

UnauthorizedException(detail: str | None = None)

crudauth.exceptions.UnprocessableEntityException

UnprocessableEntityException(detail: str | None = None)

crudauth.exceptions.DuplicateValueException

DuplicateValueException(detail: str | None = None)

crudauth.exceptions.ValueTooLongException

ValueTooLongException(limits: dict[str, int])

Bases: CustomException

A 422 in FastAPI's validation-error format, one string_too_long entry per field.

crudauth.exceptions.PasswordPolicyException

PasswordPolicyException(
    field: str, errors: list[dict[str, Any]]
)

Bases: CustomException

A 422 in FastAPI's validation-error format, one entry per unmet password rule.

crudauth.exceptions.RateLimitException

RateLimitException(
    detail: str | None = None,
    retry_after: int | None = None,
    headers: dict[str, str] | None = None,
)

crudauth.exceptions.SudoLockoutError

SudoLockoutError(
    detail: str | None = None,
    retry_after: int | None = None,
)

Bases: CustomException

Raised when too many wrong-password sudo attempts lock re-authentication.

Distinct from RateLimitException (its own sudo:* counter, separate from login lockout) but shares the 429 + Retry-After shape.

crudauth.exceptions.CSRFException

CSRFException(detail: str = 'CSRF token validation failed')

Bases: CustomException

Raised when CSRF validation fails on an unsafe (mutating) request.