drf-standardized-errors


Namedrf-standardized-errors JSON
Version 0.14.1 PyPI version JSON
download
home_pageNone
SummaryStandardize your API error responses.
upload_time2024-08-10 16:47:55
maintainerNone
docs_urlNone
authorGhazi Abbassi
requires_python>=3.8
licenseNone
keywords standardized errors errors formatter django rest framework exception handler
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # DRF Standardized Errors

Standardize your [DRF](https://www.django-rest-framework.org/) API error responses.

[![Read the Docs](https://img.shields.io/readthedocs/drf-standardized-errors)](https://drf-standardized-errors.readthedocs.io/en/latest/)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/ghazi-git/drf-standardized-errors/tests.yml?branch=main&label=Tests&logo=GitHub)](https://github.com/ghazi-git/drf-standardized-errors/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/ghazi-git/drf-standardized-errors/branch/main/graph/badge.svg?token=JXTTT1KVBR)](https://codecov.io/gh/ghazi-git/drf-standardized-errors)
[![PyPI](https://img.shields.io/pypi/v/drf-standardized-errors)](https://pypi.org/project/drf-standardized-errors/)
[![PyPI - License](https://img.shields.io/pypi/l/drf-standardized-errors)](https://github.com/ghazi-git/drf-standardized-errors/blob/main/LICENSE)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

By default, the package will convert all API error responses (4xx and 5xx) to the following standardized format:
```json
{
  "type": "validation_error",
  "errors": [
    {
      "code": "required",
      "detail": "This field is required.",
      "attr": "name"
    },
    {
      "code": "max_length",
      "detail": "Ensure this value has at most 100 characters.",
      "attr": "title"
    }
  ]
}
```
```json
{
  "type": "client_error",
  "errors": [
    {
      "code": "authentication_failed",
      "detail": "Incorrect authentication credentials.",
      "attr": null
    }
  ]
}
```
```json
{
  "type": "server_error",
  "errors": [
    {
      "code": "error",
      "detail": "A server error occurred.",
      "attr": null
    }
  ]
}
```


## Features

- Highly customizable: gives you flexibility to define your own standardized error responses and override
specific aspects the exception handling process without having to rewrite everything.
- Supports nested serializers and ListSerializer errors
- Plays nicely with error monitoring tools (like Sentry, ...)


## Requirements

- python >= 3.8
- Django >= 3.2
- DRF >= 3.12


## Quickstart

Install with `pip`
```shell
pip install drf-standardized-errors
```

Add drf-standardized-errors to your installed apps
```python
INSTALLED_APPS = [
    # other apps
    "drf_standardized_errors",
]
```

Register the exception handler
```python
REST_FRAMEWORK = {
    # other settings
    "EXCEPTION_HANDLER": "drf_standardized_errors.handler.exception_handler"
}
```

### Notes
- This package is a DRF exception handler, so it standardizes errors that reach a DRF API view. That means it cannot
handle errors that happen at the middleware level for example. To handle those as well, you can customize
the necessary [django error views](https://docs.djangoproject.com/en/dev/topics/http/views/#customizing-error-views).
You can find more about that in [this issue](https://github.com/ghazi-git/drf-standardized-errors/issues/44).

- Standardized error responses when `DEBUG=True` for **unhandled exceptions** are disabled by default. That is
to allow you to get more information out of the traceback. You can enable standardized errors instead with:
```python
DRF_STANDARDIZED_ERRORS = {"ENABLE_IN_DEBUG_FOR_UNHANDLED_EXCEPTIONS": True}
```

## Integration with DRF spectacular
If you plan to use [drf-spectacular](https://github.com/tfranzel/drf-spectacular) to generate an OpenAPI 3 schema,
install with `pip install drf-standardized-errors[openapi]`. After that, check the [doc page](https://drf-standardized-errors.readthedocs.io/en/latest/openapi.html)
for configuring the integration.

## Links

- Documentation: https://drf-standardized-errors.readthedocs.io/en/latest/
- Changelog: https://github.com/ghazi-git/drf-standardized-errors/releases
- Code & issues: https://github.com/ghazi-git/drf-standardized-errors
- PyPI: https://pypi.org/project/drf-standardized-errors/


## License

This project is [MIT licensed](LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "drf-standardized-errors",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "standardized errors, errors formatter, django rest framework, exception handler",
    "author": "Ghazi Abbassi",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/4d/cc/fd5b8cbc66c361125cba0497573a5ecac94521a715267d7db4d113257a73/drf_standardized_errors-0.14.1.tar.gz",
    "platform": null,
    "description": "# DRF Standardized Errors\n\nStandardize your [DRF](https://www.django-rest-framework.org/) API error responses.\n\n[![Read the Docs](https://img.shields.io/readthedocs/drf-standardized-errors)](https://drf-standardized-errors.readthedocs.io/en/latest/)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/ghazi-git/drf-standardized-errors/tests.yml?branch=main&label=Tests&logo=GitHub)](https://github.com/ghazi-git/drf-standardized-errors/actions/workflows/tests.yml)\n[![codecov](https://codecov.io/gh/ghazi-git/drf-standardized-errors/branch/main/graph/badge.svg?token=JXTTT1KVBR)](https://codecov.io/gh/ghazi-git/drf-standardized-errors)\n[![PyPI](https://img.shields.io/pypi/v/drf-standardized-errors)](https://pypi.org/project/drf-standardized-errors/)\n[![PyPI - License](https://img.shields.io/pypi/l/drf-standardized-errors)](https://github.com/ghazi-git/drf-standardized-errors/blob/main/LICENSE)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\nBy default, the package will convert all API error responses (4xx and 5xx) to the following standardized format:\n```json\n{\n  \"type\": \"validation_error\",\n  \"errors\": [\n    {\n      \"code\": \"required\",\n      \"detail\": \"This field is required.\",\n      \"attr\": \"name\"\n    },\n    {\n      \"code\": \"max_length\",\n      \"detail\": \"Ensure this value has at most 100 characters.\",\n      \"attr\": \"title\"\n    }\n  ]\n}\n```\n```json\n{\n  \"type\": \"client_error\",\n  \"errors\": [\n    {\n      \"code\": \"authentication_failed\",\n      \"detail\": \"Incorrect authentication credentials.\",\n      \"attr\": null\n    }\n  ]\n}\n```\n```json\n{\n  \"type\": \"server_error\",\n  \"errors\": [\n    {\n      \"code\": \"error\",\n      \"detail\": \"A server error occurred.\",\n      \"attr\": null\n    }\n  ]\n}\n```\n\n\n## Features\n\n- Highly customizable: gives you flexibility to define your own standardized error responses and override\nspecific aspects the exception handling process without having to rewrite everything.\n- Supports nested serializers and ListSerializer errors\n- Plays nicely with error monitoring tools (like Sentry, ...)\n\n\n## Requirements\n\n- python >= 3.8\n- Django >= 3.2\n- DRF >= 3.12\n\n\n## Quickstart\n\nInstall with `pip`\n```shell\npip install drf-standardized-errors\n```\n\nAdd drf-standardized-errors to your installed apps\n```python\nINSTALLED_APPS = [\n    # other apps\n    \"drf_standardized_errors\",\n]\n```\n\nRegister the exception handler\n```python\nREST_FRAMEWORK = {\n    # other settings\n    \"EXCEPTION_HANDLER\": \"drf_standardized_errors.handler.exception_handler\"\n}\n```\n\n### Notes\n- This package is a DRF exception handler, so it standardizes errors that reach a DRF API view. That means it cannot\nhandle errors that happen at the middleware level for example. To handle those as well, you can customize\nthe necessary [django error views](https://docs.djangoproject.com/en/dev/topics/http/views/#customizing-error-views).\nYou can find more about that in [this issue](https://github.com/ghazi-git/drf-standardized-errors/issues/44).\n\n- Standardized error responses when `DEBUG=True` for **unhandled exceptions** are disabled by default. That is\nto allow you to get more information out of the traceback. You can enable standardized errors instead with:\n```python\nDRF_STANDARDIZED_ERRORS = {\"ENABLE_IN_DEBUG_FOR_UNHANDLED_EXCEPTIONS\": True}\n```\n\n## Integration with DRF spectacular\nIf you plan to use [drf-spectacular](https://github.com/tfranzel/drf-spectacular) to generate an OpenAPI 3 schema,\ninstall with `pip install drf-standardized-errors[openapi]`. After that, check the [doc page](https://drf-standardized-errors.readthedocs.io/en/latest/openapi.html)\nfor configuring the integration.\n\n## Links\n\n- Documentation: https://drf-standardized-errors.readthedocs.io/en/latest/\n- Changelog: https://github.com/ghazi-git/drf-standardized-errors/releases\n- Code & issues: https://github.com/ghazi-git/drf-standardized-errors\n- PyPI: https://pypi.org/project/drf-standardized-errors/\n\n\n## License\n\nThis project is [MIT licensed](LICENSE).\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Standardize your API error responses.",
    "version": "0.14.1",
    "project_urls": {
        "Changelog": "https://github.com/ghazi-git/drf-standardized-errors/releases",
        "Code": "https://github.com/ghazi-git/drf-standardized-errors",
        "Documentation": "https://drf-standardized-errors.readthedocs.io/en/latest/",
        "Homepage": "https://github.com/ghazi-git/drf-standardized-errors",
        "Issues": "https://github.com/ghazi-git/drf-standardized-errors/issues"
    },
    "split_keywords": [
        "standardized errors",
        " errors formatter",
        " django rest framework",
        " exception handler"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4470589efc32d6f268576e2f3c2a595ef19a305c5d5acbfd26d10ebd45278778",
                "md5": "6fdddf8fedab7dfd5df62def55a2139e",
                "sha256": "4941e0f81be94eb0904549999cf221988a5b0f524041c3877530e24f70328ed8"
            },
            "downloads": -1,
            "filename": "drf_standardized_errors-0.14.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6fdddf8fedab7dfd5df62def55a2139e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 25512,
            "upload_time": "2024-08-10T16:47:53",
            "upload_time_iso_8601": "2024-08-10T16:47:53.411847Z",
            "url": "https://files.pythonhosted.org/packages/44/70/589efc32d6f268576e2f3c2a595ef19a305c5d5acbfd26d10ebd45278778/drf_standardized_errors-0.14.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4dccfd5b8cbc66c361125cba0497573a5ecac94521a715267d7db4d113257a73",
                "md5": "5050ab078a393cd9000a0460abc65990",
                "sha256": "0610dcd0096b75365102d276022a22e59a1f8db8825bb0bff05e1b7194ba145d"
            },
            "downloads": -1,
            "filename": "drf_standardized_errors-0.14.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5050ab078a393cd9000a0460abc65990",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 58730,
            "upload_time": "2024-08-10T16:47:55",
            "upload_time_iso_8601": "2024-08-10T16:47:55.912397Z",
            "url": "https://files.pythonhosted.org/packages/4d/cc/fd5b8cbc66c361125cba0497573a5ecac94521a715267d7db4d113257a73/drf_standardized_errors-0.14.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-10 16:47:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ghazi-git",
    "github_project": "drf-standardized-errors",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "drf-standardized-errors"
}
        
Elapsed time: 5.05990s