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.2.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for drf-standardized-errors-0.10.2.tar.gz
Algorithm Hash digest
SHA256 ccc46d78455b1438c40d01567e5c47b8c141b61bde37dc8d62ecf5bf4e87b3ee
MD5 eca2afe25dfbe6852c66f30728487c7e
BLAKE2b-256 7840b0ee3a4cc1718a9f774ceba1f7ff34c1514a3a52ea3b0b6c4f30a79f71d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_standardized_errors-0.10.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a693c8e1eefbc040395839c555f645591f1f75c717ea0b87c4ccc1a4a6552f51
MD5 88054892978d35ac231b773ff91dea87
BLAKE2b-256 8d4d5a00956c7916c7aff55bbf322b24377adaadfc8c18ed0adb05109e227e29

See more details on using hashes here.

Supported by

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