Skip to main content

Django Rest Framework pretty exception handler

Project description

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.

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_pretty_exception_handler-0.1.3.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

drf_pretty_exception_handler-0.1.3-py2.py3-none-any.whl (4.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file drf_pretty_exception_handler-0.1.3.tar.gz.

File metadata

  • Download URL: drf_pretty_exception_handler-0.1.3.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for drf_pretty_exception_handler-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b34a96cb027a7d8f589c46eec6a6ec192ca5fdc9751ed61855e40f995b8ff329
MD5 64efdf3745c6440364c7336b5f7851ae
BLAKE2b-256 e4a60a08861fc1c0908c00d3f009e221665296391d4c26905813e90ce8298b1d

See more details on using hashes here.

File details

Details for the file drf_pretty_exception_handler-0.1.3-py2.py3-none-any.whl.

File metadata

  • Download URL: drf_pretty_exception_handler-0.1.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for drf_pretty_exception_handler-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2402e98a5a2046072d6c3757451372b973b512d28e04b31470ad08696cd1f624
MD5 ee4d74dc915379c9aadf09c334923dd8
BLAKE2b-256 695fa4af06f599093c29ecc1ca15184294861dc2eeecce8ce02a061d755bbcef

See more details on using hashes here.

Supported by

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