Skip to main content

drf-common-exceptions

Release CI Coverage
pypi build codecov

Common exception for Django REST framework. Provides single generic interface of returning data structure for any kind of exceptions which are handled by Django REST framework. Includes error name, path to service with line where the error occurs and a list of actual error messages with extended fields info.

Requirements

  • Python (3.6+)
  • Django (1.11.x, 2.0+)
  • Django REST Framework (3.7+)

Installation

$ pip install drf-common-exceptions

Usage examples

You can define common exception handler for whole project. Just put the following line to your django settings inside drf section:

REST_FRAMEWORK = {
  ...
  "EXCEPTION_HANDLER": "drf_common_exceptions.common_exception_handler",
  ...
}

Or use it just for particular view or viewset:

from drf_common_exceptions import CommonExceptionHandlerMixin

class MyView(CommonExceptionHandlerMixin, APIView):
    pass

The output will looks like for example validation error:

{
    "service": "path.to.views.MyView:20",
    "error": "ValidationError",
    "detail": [
        {
            "label": "Name",
            "field": "name",
            "messages": [
                "This is required field."
            ]
        }
    ]
}

The data structure will be the same for any other errors.

Development

Install poetry and requirements:

$ curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
$ python3 -m venv path/to/venv
$ source path/to/venv/bin/activate
$ poetry install

Run main commands:

$ make test
$ make watch
$ make clean
$ make lint

Publish to pypi be default patch version:

$ make publish

or any level you want:

$ make publish minor

Metadata

Release files for drf-common-exceptions 0.1.1

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-common-exceptions 0.1.1
File Size Uploaded
drf-common-exceptions-0.1.1.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drf-common-exceptions 0.1.1
File Interpreter ABI Platform
drf_common_exceptions-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / drf-common-exceptions-0.1.1.tar.gz

Download URL drf-common-exceptions-0.1.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c9224deb7b5bd1558828effd06bc0dee81434bae4fa08a10b49c57c02dc1911b
BLAKE2b-256 checksum
How to use checksums
2908c66c1ee0b2a71898a8e99a820308e1008dc1c60ccabcc4148997e5ae2ef5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.11 CPython/3.6.7 Linux/4.15.0-34-generic

Release files / drf_common_exceptions-0.1.1-py3-none-any.whl

Download URL drf_common_exceptions-0.1.1-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b7ce27f54a58188c24992645465a98d8a5cbb4c7afe8c3b7615b76cecd2c6b8
BLAKE2b-256 checksum
How to use checksums
fa7bda4ec6464bd5e52c841db81f2727888f16e5c168ff878b96217003267340
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.11 CPython/3.6.7 Linux/4.15.0-34-generic

Release history Release notifications | RSS feed

This release

0.1.1 This release

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