Error handling pipeline for chirp requests.
Maps HTTPError exceptions and unexpected failures to appropriate Response objects, using registered error handlers or sensible defaults.
server.errors
| Name | Type | Default | Description |
|---|---|---|---|
type
|
|
— | |
qualified_name
|
|
— | |
element_type
|
|
— | |
description
|
|
— | |
source_file
|
|
— | |
line_number
|
|
— | |
is_autodoc
|
|
— | |
autodoc_element
|
|
— | |
_autodoc_template
|
|
— | |
_autodoc_url_path
|
|
— | |
_autodoc_page_type
|
|
— | |
title
|
|
— | |
doc_content_hash
|
|
— |
Symbols on this page
Return exception headers plus route-scoped QUERY discovery metadata.
Minimal HTML snippet for fragment error responses.
Add htmx error-handling headers when the request is an htmx request.
Headers added:
HX-Retarget: #chirp-error— redirect error content to a dedicated containerHX-Reswap:…
Invoke a user-registered error handler with introspected arguments.
Error handlers may accept zero, one (request), or two (request, exc) args. Supports both sync and…
Map an HTTPError to a Response using registered error handlers.
Handle unexpected exceptions as 500 errors.
_error_headers
function
def _error_headers(exc: HTTPError, request: Request) -> tuple[tuple[str, str], ...]
Return exception headers plus route-scoped QUERY discovery metadata.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
exc
|
HTTPError
|
— | |
request
|
Request
|
— |
default_fragment_error
function
def default_fragment_error(status: int, detail: str) -> str
Minimal HTML snippet for fragment error responses.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
status
|
int
|
— | |
detail
|
str
|
— |
_with_htmx_error_headers
function
def _with_htmx_error_headers(response: Response, request: Request) -> Response
Add htmx error-handling headers when the request is an htmx request.
Headers added:
HX-Retarget: #chirp-error— redirect error content to a dedicated containerHX-Reswap: innerHTML— replace (not append) the error contentHX-Trigger: chirpError— fire a client-side event for custom handling
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
response
|
Response
|
— | |
request
|
Request
|
— |
call_error_handler
function
async
async def call_error_handler(handler: Callable[..., Any], request: Request, exc: Exception, kida_env: Environment | None, oob_registry: OOBRegistry | None = None, fragment_target_registry: FragmentTargetRegistry | None = None) -> Response | StreamingResponse | SSEResponse
Invoke a user-registered error handler with introspected arguments.
Error handlers may accept zero, one (request), or two (request, exc) args. Supports both sync and async error handlers.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
handler
|
Callable[..., Any]
|
— | |
request
|
Request
|
— | |
exc
|
Exception
|
— | |
kida_env
|
Environment | None
|
— | |
oob_registry
|
OOBRegistry | None
|
None
|
|
fragment_target_registry
|
FragmentTargetRegistry | None
|
None
|
handle_http_error
function
async
async def handle_http_error(exc: HTTPError, request: Request, error_handlers: dict[int | type, Callable[..., Any]], kida_env: Environment | None, debug: bool, oob_registry: OOBRegistry | None = None, fragment_target_registry: FragmentTargetRegistry | None = None) -> Response | StreamingResponse | SSEResponse
Map an HTTPError to a Response using registered error handlers.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
exc
|
HTTPError
|
— | |
request
|
Request
|
— | |
error_handlers
|
dict[int | type, Callable[..., Any]]
|
— | |
kida_env
|
Environment | None
|
— | |
debug
|
bool
|
— | |
oob_registry
|
OOBRegistry | None
|
None
|
|
fragment_target_registry
|
FragmentTargetRegistry | None
|
None
|
handle_internal_error
function
async
async def handle_internal_error(exc: Exception, request: Request, error_handlers: dict[int | type, Callable[..., Any]], kida_env: Environment | None, debug: bool, oob_registry: OOBRegistry | None = None, fragment_target_registry: FragmentTargetRegistry | None = None) -> Response | StreamingResponse | SSEResponse
Handle unexpected exceptions as 500 errors.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
exc
|
Exception
|
— | |
request
|
Request
|
— | |
error_handlers
|
dict[int | type, Callable[..., Any]]
|
— | |
kida_env
|
Environment | None
|
— | |
debug
|
bool
|
— | |
oob_registry
|
OOBRegistry | None
|
None
|
|
fragment_target_registry
|
FragmentTargetRegistry | None
|
None
|
View source · /home/runner/work/chirp/chirp/site/../src/chirp/server/errors.py:1