Skip to content

Exceptions

rn_forge.django.exceptions

Django exception handlers for legacy JSON and RFC 9457 responses.

django_exception_handler(request, *args, **kwargs)

Handle plain Django exceptions with a normalized JSON response.

json_exception_response(request, error, message, status_code)

Build a normalized JSON response for handled exceptions.

problem_details_handler404(request, exception=None)

Render an unmatched Django route as a problem response.

problem_details_handler500(request)

Render an exception escaping a plain Django view as a problem.

problem_details_response(exc, *, instance, registry, problem=None, detail=None, extensions=None, headers=None)

Render exc as an application/problem+json response.

Includes the current trace id. A 401 uses a generic detail and adds a WWW-Authenticate challenge unless headers already contains one.

Parameters:

Name Type Description Default
exc BaseException

The exception being rendered.

required
instance str

The instance member — in practice the request path.

required
registry ProblemRegistry

The rows to render with.

required
problem ProblemType | None

The row to use instead of resolving one from exc.

None
detail str | None

Overrides the registry's derived detail.

None
extensions Mapping[str, Any] | None

Extra members, flattened onto the body.

None
headers Mapping[str, str] | None

Response headers to carry, e.g. a DRF-built challenge.

None

register_django_exception_handlers()

Register :func:django_exception_handler as the global Django handler.