Skip to main content

Standardize your API error responses.

Project description

DRF Standardized Errors

Standardize your DRF API error responses.

Read the Docs GitHub Workflow Status codecov PyPI PyPI - License Code style: black

By default, the API error responses (4xx and 5xx) will look like:

{
  "type": "validation_error",
  "errors": [
    {
      "code": "required",
      "detail": "This field is required.",
      "attr": "name"
    }
  ]
}

Features

  • Highly customizable: gives you flexibility to define your own standardized error responses and override specific aspects the exception handling process without having to rewrite everything.
  • Supports nested serializers and ListSerializer errors
  • Plays nicely with error monitoring tools (like Sentry, ...)

Requirements

  • python >= 3.8
  • Django >= 3.2
  • DRF >= 3.12

Quickstart

Install with pip

pip install drf-standardized-errors

Add drf-standardized-errors to your installed apps

INSTALLED_APPS = [
    # other apps
    "drf_standardized_errors",
]

Register the exception handler

REST_FRAMEWORK = {
    # other settings
    "EXCEPTION_HANDLER": "drf_standardized_errors.exception_handler"
}

Notes

Standardized error responses when DEBUG=True for unhandled exceptions are disabled by default. That is to allow you to get more information out of the traceback. You can enable standardized errors instead with:

DRF_STANDARDIZED_ERRORS = {"ENABLE_IN_DEBUG_FOR_UNHANDLED_EXCEPTIONS": True}

Links

Licence

This project is MIT licensed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drf-standardized-errors-0.10.0.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drf_standardized_errors-0.10.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file drf-standardized-errors-0.10.0.tar.gz.

File metadata

File hashes

Hashes for drf-standardized-errors-0.10.0.tar.gz
Algorithm Hash digest
SHA256 848a2128a8d6f0aadb97fa27894a87727b73b03fe63f43d836f2a498f41227c1
MD5 e23235b899fa0eee31cf48f683364491
BLAKE2b-256 b522134842adcff6d0e3a6235d18619db19777d69c87e86ee94987c828adead7

See more details on using hashes here.

File details

Details for the file drf_standardized_errors-0.10.0-py3-none-any.whl.

File metadata

File hashes

Hashes for drf_standardized_errors-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e368c0c9dcd942ba533fdd02810a3b681c64d25be983ec49035bd37beb665a2
MD5 54edafc58dd1a51f910ce2b0c54c01ee
BLAKE2b-256 9173fb8c6ab9178012f7ed92022df41fe3a9ca7efce75e1f47eeaa57a7425f39

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page