Coverage for src / lexigram / contracts / auth / exceptions.py: 88%
16 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
1"""Auth domain base error hierarchy.
3These are the base exception types that any package can catch at the
4auth-domain boundary without depending on ``lexigram-auth``.
6Infrastructure failures (cache down, network errors, configuration errors)
7must still be raised as exceptions — do not wrap them in ``Result``.
9Leaf exceptions (``InvalidCredentialsError``, ``TokenExpiredError``, etc.)
10live in ``lexigram.auth.exceptions`` — import from there when you need to
11distinguish specific auth failure modes.
13Error hierarchy
14---------------
15::
17 AuthError Base for all auth-domain failures
18 TokenError Base for all expected token failures
19 VerificationError Base for all account-verification failures
20"""
22from __future__ import annotations
24from typing import Any
26from lexigram.contracts.exceptions.domain import DomainError
29class AuthError(DomainError):
30 """Base exception for all auth-domain errors.
32 This is the catch-all for authentication and authorization failures
33 that clients are expected to handle gracefully.
34 """
36 _code = "LEX_ERR_AUTH_001"
38 def __init__(
39 self,
40 message: str = "Auth error",
41 **kwargs: Any,
42 ) -> None:
43 super().__init__(message, **kwargs)
46class TokenError(DomainError):
47 """Base class for expected, recoverable token domain failures.
49 All subtypes indicate situations the caller is expected to handle
50 gracefully (e.g. reject the request, ask for re-authentication).
51 """
53 _code = "LEX_ERR_AUTH_002"
55 def __init__(
56 self,
57 message: str = "Token error",
58 **kwargs: Any,
59 ) -> None:
60 super().__init__(message, **kwargs)
63class VerificationError(DomainError):
64 """Base class for expected, recoverable account-verification failures.
66 All subtypes signal situations the caller should handle gracefully
67 (e.g. redirect to a re-verification page or surface a user-facing error).
68 """
70 _code = "LEX_ERR_AUTH_003"
72 def __init__(
73 self,
74 message: str = "Account verification error",
75 **kwargs: Any,
76 ) -> None:
77 super().__init__(message, **kwargs)
80__all__ = [
81 "AuthError",
82 "TokenError",
83 "VerificationError",
84]