Skip to main content

Django Rest Framework pretty exception handler

https://pypi.python.org/pypi/drf_pretty_exception_handler https://travis-ci.com/ivlevdenis/drf_pretty_exception_handler https://drf-pretty-exception-handler.readthedocs.io/en/latest/?badge=latest https://pyup.io/repos/github/ivlevdenis/drf_pretty_exception_handler/

Django Rest Framework pretty exception handler

Dependencies

  • Python 3.7+
  • Django 2.0+
  • Django Rest Framework 3.10+

Setup

You can install the library directly from pypi using pip:

$ pip install drf-pretty-exception-handler

Edit your REST_FRAMEWORK settings in settings.py file:

REST_FRAMEWORK = {
    ...
    'EXCEPTION_HANDLER': 'drf_pretty_exception_handler.exception_handler',
    ...
}

License

Free software: MIT license

Features

Default Django Rest Framework exception handler return errors in different formats.

Examples: Response on raise exceptions.APIException.

{
  "detail": "A server error occurred."
}

Response on raise exceptions.ValidationError.

[
  "Invalid input."
]

Response on raise exceptions.ValidationError if error in field serializator.

{
  "email": [
    "This field is required."
  ]
}

Response on raise exceptions.ValidationError in serializator .validate() .

{
  "non_field_errors": [
    "Passwords does not match"
  ]
}

This greatly complicates error handling in the frontend. This package provide own format of errors.

{
  "status_code": 500,
  "errors": {
    "non_field_errors": [
      "A server error occurred."
    ]
  }
}
{
  "status_code": 400,
  "errors": {
    "non_field_errors": [
      "Invalid input."
    ]
  }
}
{
  "status_code": 400,
  "errors": {
    "email": [
      "This field is required."
    ]
  }
}
{
  "status_code": 400,
  "errors": {
    "non_field_errors": [
      "Passwords does not match"
    ]
  }
}

And this package handle default Python exceptions.

l = [1, 2, 3, 4]
l[10]
{
  "status_code": 500,
  "errors": {
    "non_field_errors": [
      "IndexError: list index out of range"
    ]
  }
}

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Metadata

Release files for drf-pretty-exception-handler 0.1.3

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-pretty-exception-handler 0.1.3
File Size Uploaded
drf_pretty_exception_handler-0.1.3.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drf-pretty-exception-handler 0.1.3
File Interpreter ABI Platform
drf_pretty_exception_handler-0.1.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 15.8 kB

Release files / drf_pretty_exception_handler-0.1.3.tar.gz

Download URL drf_pretty_exception_handler-0.1.3.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b34a96cb027a7d8f589c46eec6a6ec192ca5fdc9751ed61855e40f995b8ff329
BLAKE2b-256 checksum
How to use checksums
e4a60a08861fc1c0908c00d3f009e221665296391d4c26905813e90ce8298b1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.7.1 requests/2.26.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2

Release files / drf_pretty_exception_handler-0.1.3-py2.py3-none-any.whl

Download URL drf_pretty_exception_handler-0.1.3-py2.py3-none-any.whl
Size 4.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2402e98a5a2046072d6c3757451372b973b512d28e04b31470ad08696cd1f624
BLAKE2b-256 checksum
How to use checksums
695fa4af06f599093c29ecc1ca15184294861dc2eeecce8ce02a061d755bbcef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.7.1 requests/2.26.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

3 release files

0.1.1

2 release files

0.1.0

2 release files

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