Problem
rn_forge.fastapi.problem
Render FastAPI and Starlette failures as RFC 9457 problem responses.
Register application exception mappings before installing the handlers so Starlette dispatches them through its typed exception middleware. The fallback handler also logs the current trace id.
Log = Callable[[str, Mapping[str, Any]], None]
The injected logging sink, called as log(event, context).
log_server_errors(logger=None)
Return a :data:Log that logs each 5xx problem at ERROR, with its traceback.
The record carries the event, status, instance and trace id in its message
and the exception's traceback as exc_info. Events other than
problem.server_error are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
AppLogger | None
|
Where to log. Defaults to
|
None
|
Example::
AppConfig(log=log_server_errors())
register_problem_handlers(app, *, registry=None, realm=None, log=None)
Render every error app produces as application/problem+json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
FastAPI
|
The application. Call this once while building it; nothing is registered on import. |
required |
registry
|
ProblemRegistry | None
|
The rows to render with. Defaults to a fresh
:func: |
None
|
realm
|
str | None
|
The |
None
|
log
|
Log | None
|
Called as |
None
|