Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abogoyavlensky/drf-common-exceptions
Common exceptions handler for Django REST framework
https://github.com/abogoyavlensky/drf-common-exceptions
django django-rest-framework exceptions python
Last synced: 5 days ago
JSON representation
Common exceptions handler for Django REST framework
- Host: GitHub
- URL: https://github.com/abogoyavlensky/drf-common-exceptions
- Owner: abogoyavlensky
- Created: 2019-02-16T20:36:36.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T02:00:41.000Z (about 2 years ago)
- Last Synced: 2024-12-10T07:57:28.015Z (about 1 month ago)
- Topics: django, django-rest-framework, exceptions, python
- Language: Python
- Homepage:
- Size: 59.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
drf-common-exceptions
===| Release | CI | Coverage |
|---------|----|----------|
|[![pypi](https://img.shields.io/pypi/v/drf-common-exceptions.svg)](https://pypi.python.org/pypi/drf-common-exceptions)|[![build](https://img.shields.io/travis/com/abogoyavlensky/drf-common-exceptions.svg)](https://travis-ci.com/abogoyavlensky/drf-common-exceptions)|[![codecov](https://img.shields.io/codecov/c/github/abogoyavlensky/drf-common-exceptions.svg)](https://codecov.io/gh/abogoyavlensky/drf-common-exceptions)|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
```bash
$ 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:
```python
from drf_common_exceptions import CommonExceptionHandlerMixinclass MyView(CommonExceptionHandlerMixin, APIView):
pass
```The output will looks like for example validation error:
```json
{
"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:
```bash
$ 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:
```bash
$ make test
$ make watch
$ make clean
$ make lint
```Publish to pypi by default patch version:
```bash
$ make publish
```or any level you want:
```bash
$ make publish minor
```