drf-standardized-errors


Namedrf-standardized-errors JSON
Version 0.13.0 PyPI version JSON
download
home_pageNone
SummaryStandardize your API error responses.
upload_time2024-02-28 19:22:36
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/d8/6a/49ad0e30360d59f39a23742b2e56c4ecc268e19410a117df3fd990c7aafc/drf_standardized_errors-0.13.0.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.13.0",
    "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": "1d97af7498d7ea9b9fe890b93c4f93ce21f3c19eb14bd1ec35d8a95c8f49c09e",
                "md5": "72bf9ae1b55b8a18e1784cf584c12153",
                "sha256": "ee6513f1e289f02a62ed447fee2608dab12b5687817c9bcb429587658d4ad3aa"
            },
            "downloads": -1,
            "filename": "drf_standardized_errors-0.13.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "72bf9ae1b55b8a18e1784cf584c12153",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 25332,
            "upload_time": "2024-02-28T19:22:34",
            "upload_time_iso_8601": "2024-02-28T19:22:34.155076Z",
            "url": "https://files.pythonhosted.org/packages/1d/97/af7498d7ea9b9fe890b93c4f93ce21f3c19eb14bd1ec35d8a95c8f49c09e/drf_standardized_errors-0.13.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d86a49ad0e30360d59f39a23742b2e56c4ecc268e19410a117df3fd990c7aafc",
                "md5": "46ddf684e0caede0fc4d7ffc363764e2",
                "sha256": "f18b2b7f40c9f04f9023bb5f74fb451462cb50d1484ea2ebb94f3774d14993bf"
            },
            "downloads": -1,
            "filename": "drf_standardized_errors-0.13.0.tar.gz",
            "has_sig": false,
            "md5_digest": "46ddf684e0caede0fc4d7ffc363764e2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 57567,
            "upload_time": "2024-02-28T19:22:36",
            "upload_time_iso_8601": "2024-02-28T19:22:36.787887Z",
            "url": "https://files.pythonhosted.org/packages/d8/6a/49ad0e30360d59f39a23742b2e56c4ecc268e19410a117df3fd990c7aafc/drf_standardized_errors-0.13.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-28 19:22:36",
    "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: 0.18778s