Skip to content

infrastructure.errors.infrastructure_error

src.infrastructure.errors.infrastructure_error

Infrastructure layer error types.

Infrastructure errors represent failures in external systems (database, cache, providers).

Architecture: - Infrastructure catches exceptions and maps to DomainError - Infrastructure errors inherit from DomainError (not Exception) - Uses InfrastructureErrorCode for internal error tracking - Maps to domain ErrorCode when flowing to domain layer - Used with Result types for error propagation

Classes

InfrastructureError dataclass

Bases: DomainError

Base infrastructure error.

Infrastructure errors still use domain ErrorCode enum (not InfrastructureErrorCode). The InfrastructureErrorCode is for internal infrastructure tracking only.

Attributes:

Name Type Description
code ErrorCode

Domain ErrorCode (maps from InfrastructureErrorCode).

message str

Human-readable message.

infrastructure_code InfrastructureErrorCode | None

Original infrastructure error code.

details dict[str, Any] | None

Additional context.

Source code in src/infrastructure/errors/infrastructure_error.py
@dataclass(frozen=True, slots=True, kw_only=True)
class InfrastructureError(DomainError):
    """Base infrastructure error.

    Infrastructure errors still use domain ErrorCode enum (not InfrastructureErrorCode).
    The InfrastructureErrorCode is for internal infrastructure tracking only.

    Attributes:
        code: Domain ErrorCode (maps from InfrastructureErrorCode).
        message: Human-readable message.
        infrastructure_code: Original infrastructure error code.
        details: Additional context.
    """

    infrastructure_code: InfrastructureErrorCode | None = None
    details: dict[str, Any] | None = None

DatabaseError dataclass

Bases: InfrastructureError

Database-specific errors.

Wraps SQLAlchemy exceptions and provides consistent error handling.

Attributes:

Name Type Description
code ErrorCode

Domain ErrorCode.

message str

Human-readable message.

infrastructure_code InfrastructureErrorCode | None

Database-specific error code.

details dict[str, Any] | None

Additional context (constraint name, original error).

Source code in src/infrastructure/errors/infrastructure_error.py
@dataclass(frozen=True, slots=True, kw_only=True)
class DatabaseError(InfrastructureError):
    """Database-specific errors.

    Wraps SQLAlchemy exceptions and provides consistent error handling.

    Attributes:
        code: Domain ErrorCode.
        message: Human-readable message.
        infrastructure_code: Database-specific error code.
        details: Additional context (constraint name, original error).
    """

    pass

CacheError dataclass

Bases: InfrastructureError

Cache-specific errors.

Wraps Redis/cache exceptions and provides consistent error handling.

Attributes:

Name Type Description
code ErrorCode

Domain ErrorCode.

message str

Human-readable message.

infrastructure_code InfrastructureErrorCode | None

Cache-specific error code.

details dict[str, Any] | None

Additional context (key, operation, original error).

Source code in src/infrastructure/errors/infrastructure_error.py
@dataclass(frozen=True, slots=True, kw_only=True)
class CacheError(InfrastructureError):
    """Cache-specific errors.

    Wraps Redis/cache exceptions and provides consistent error handling.

    Attributes:
        code: Domain ErrorCode.
        message: Human-readable message.
        infrastructure_code: Cache-specific error code.
        details: Additional context (key, operation, original error).
    """

    pass

ExternalServiceError dataclass

Bases: InfrastructureError

External service integration errors.

Used for non-provider external services like email, SMS, payment gateways.

Attributes:

Name Type Description
code ErrorCode

Domain ErrorCode.

message str

Human-readable message.

infrastructure_code InfrastructureErrorCode | None

Service-specific error code.

service_name str

Name of the external service.

details dict[str, Any] | None

Additional context (status code, response).

Source code in src/infrastructure/errors/infrastructure_error.py
@dataclass(frozen=True, slots=True, kw_only=True)
class ExternalServiceError(InfrastructureError):
    """External service integration errors.

    Used for non-provider external services like email, SMS, payment gateways.

    Attributes:
        code: Domain ErrorCode.
        message: Human-readable message.
        infrastructure_code: Service-specific error code.
        service_name: Name of the external service.
        details: Additional context (status code, response).
    """

    service_name: str