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

  • 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.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

drf_pretty_exception_handler-0.1.0-py2.py3-none-any.whl (4.4 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: drf_pretty_exception_handler-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for drf_pretty_exception_handler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 143cadc529a1da35985d69c2444fb052811c24b18c55bd9ccd2c01c4da5b01a7
MD5 04915e8b42c62b4bea609de47640a08a
BLAKE2b-256 cd0b60e3e6739af529ca418104252c619d9695ed5a901095a003cb6d79503f5a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: drf_pretty_exception_handler-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for drf_pretty_exception_handler-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 50860b7beb2b6d7f8a8e6d4485a70f6a13012e522761881dcfe05525687c2db6
MD5 0af70bedf30ca1e41d2b4be167decd64
BLAKE2b-256 4ba3e5ef99b1282e24d428f62f6f6d7272800f38c82871c2b078e00d59b8e58b

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