Skip to main content

Django REST framework exception dispatcher

django-rest-framework exception handler build with funtools.singledispatch.

Installation

To use drf-exception-dispatcher simply install it with your package manager, e.g. to with pip:

pip install drf-exception-dispatcher

Then simply use exception_dispatcher.handlers.exception_handler ( or your own exception handler built on exception_dispatcher) in Django's settings REST_FRAMEWORK section:

REST_FRAMEWORK = {
  # ...
  'EXCEPTION_HANDLER': 'exception_dispatcher.handlers.exception_handler',
  # ...
}

Configuration

Following settings are present to make default exception_dispatcher handler configurable:

  • EXCEPTION_DISPATCHER_SET_ROLLBACK (defaults to True) - indicate if set_rollback should be called before returning response from exception handler
  • EXCEPTION_DISPATCHER_API_EXCEPTION_PARSER (defaults to exception_dispatcher.parsers.parse_rest_framework_api_exception') - import path to callable that is used to translate occurred exception to response data

Usage

To add new handlers to exception_dispatchers simply use dispatcher's register() method, e.g. to add handler of SuspiciousOperation exceptions:

from exception_dispatcher.dispatchers import exception_dispatcher
from exception_dispatcher.types import ContextType
from rest_framework.response import Response


@exception_dispatcher.register
def handler_suspicious_operation(
    exception: SuspiciousOperation,
    context: ContextType,
) -> Response | None:
    """Handle Django's `SuspiciousOperation` exceptions."""
    # custom ``exception` handler logic goes here
    return None

Metadata

Release files for drf-exception-dispatcher 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drf-exception-dispatcher 0.1.0
File Size Uploaded Provenance Actions
drf-exception-dispatcher-0.1.0.tar.gz 5.6 kB Without provenance Details for drf-exception-dispatcher-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for drf-exception-dispatcher 0.1.0
File Interpreter ABI Platform Actions
drf_exception_dispatcher-0.1.0-py3-none-any.whl Python 3 none any Details for drf_exception_dispatcher-0.1.0-py3-none-any.whl

Total release size: 13.4 kB

Release files / drf-exception-dispatcher-0.1.0.tar.gz

Download URL drf-exception-dispatcher-0.1.0.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c005798dd266716a1b21f2de6322cc1486a4e8b8f69ab4b7cb887b36a4afbe51
BLAKE2b-256 checksum
How to use checksums
297bffc9b69a2bab10cb4eebfba36b6723f9ba1ff46eef6d859c3a36ba2a97e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.10.0 Linux/5.11.0-1020-azure

Release files / drf_exception_dispatcher-0.1.0-py3-none-any.whl

Download URL drf_exception_dispatcher-0.1.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6064e938ee4f1c023db96d260624bd5f186a30fea5b3e17899b0dcac2f214568
BLAKE2b-256 checksum
How to use checksums
fcc49a80d1abf82595feadd5112158cb9edf72148ba4712a8b75d962a05a3d46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.10.0 Linux/5.11.0-1020-azure

Security for drf-exception-dispatcher 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page