Fault Handlers — Aquilia Documentation
Comprehensive guide and documentation for Fault Handlers in the Aquilia framework. View API reference, examples, and implementation patterns.
FAULTS / FAULT HANDLERS Fault Handlers Custom handlers resolve propagating Faults. By implementing a two-method contract, handlers can intercept errors, translate them, or format custom responses. The FaultHandler Contract Every custom handler must inherit from FaultHandler and implement exactly two methods: Evaluates the FaultContext predicate. Returns True if this handler claims responsibility for the fault, allowing .handle() to run. Executes the resolution logic. Must return Resolved(response), Transformed(new_fault), or Escalate(). Writing a Custom Handler from aquilia.faults import FaultHandler, Resolved, Escalate, FaultResult from aquilia.response import Response class DatabaseConnectionFaultHandler(FaultHandler): """Custom handler for database outage faults.""" def can_handle(self, ctx) -> bool: # Match only DB-related faults with severe status return ctx.fault.domain.value == "model" and ctx.fault.code.startswith("DB_") async def handle(self, ctx) -> FaultResult: # Log active request variables print(f"Database error on: - ") if ctx.fault.retryable: # Let it escalate to a retry middleware return Escalate() # Return a structured JSON response return Resolved( Response( , status=503 ) ) FaultEngine Fault Domains )
Go to Homepage