Skip to content

Exceptions

Which handler do I want?

Two exception handlers ship, and this package wires neither — name one in REST_FRAMEWORK["EXCEPTION_HANDLER"]:

  • problem_details_exception_handler renders RFC 9457 application/problem+json. It is the wire contract shared with rn-forge-fastapi, so choose it for any new API. The normative description of the body, the status mapping and the 401/403 boundary is rn-forge-web's api-conventions.md; this page does not restate it.
  • drf_exception_handler renders this package's original {"path", "error", "message"} body, for existing consumers.

For Django's own routing errors, name rn_forge.django.exceptions.problem_details_handler404 (and problem_details_handler500) in your root URLconf — see Exceptions.

rn_forge.django.drf.exceptions

DRF exception handlers for legacy JSON and RFC 9457 responses.

No error library is adopted: drf-standardized-errors 0.16.0 (checked 2026-09-23) has no RFC 9457 mode, so its application/json body lacks title, status, instance and pointer-based errors.

NO_CHALLENGE = 'x-rn-forge-no-challenge' module-attribute

An authenticate_header value that makes DRF answer 401 while :func:problem_details_exception_handler sends no WWW-Authenticate.

drf_exception_handler(exc, context)

Handle DRF exceptions with a normalized JSON response.

problem_details_exception_handler(exc, context, *, registry=None)

Render an exception as an RFC 9457 application/problem+json response.

DRF determines the status and headers first; the registry then supplies the problem body. Validation field errors appear in the errors extension. A WWW-Authenticate value of :data:NO_CHALLENGE is dropped.

Parameters:

Name Type Description Default
exc Exception

The exception DRF caught.

required
context Mapping[str, object]

DRF's handler context; context["request"] gives the path.

required
registry ProblemRegistry | None

The rows to render with. Defaults to :func:problem_registry with RN_FORGE_DJANGO["AUTH"]["PROBLEM_TYPE_BASE"] when set.

None

problem_registry(*, type_base='')

Return the default problem registry with DRF validation mapped to 422.

Also maps Django's own RequestDataTooBig (raised when a body exceeds DATA_UPLOAD_MAX_MEMORY_SIZE) to 413 — Django's default is 400 — and TooManyFieldsSent and TooManyFilesSent (raised past DATA_UPLOAD_MAX_NUMBER_FIELDS and DATA_UPLOAD_MAX_NUMBER_FILES) to 400.

Parameters:

Name Type Description Default
type_base str

Forwarded to :func:rn_forge.web.default_registry.

''