{"id":6350,"library":"drf-standardized-errors","title":"DRF Standardized Errors","description":"drf-standardized-errors is a Python library for Django REST Framework that standardizes API error responses, making them consistent and easier for clients to consume. It is currently at version 0.15.0 and maintains an active release cadence, frequently adding support for new Python, Django, and DRF versions.","status":"active","version":"0.15.0","language":"en","source_language":"en","source_url":"https://github.com/ghazi-git/drf-standardized-errors","tags":["django","drf","api","errors","exception-handling","openapi","rest-framework"],"install":[{"cmd":"pip install drf-standardized-errors","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for integrating with Django REST Framework.","package":"djangorestframework","optional":false},{"reason":"Optional dependency for OpenAPI schema generation, providing error response examples and enhanced schema support.","package":"drf-spectacular","optional":true}],"imports":[{"note":"The exception handler is located in the 'handler' submodule.","wrong":"from drf_standardized_errors import exception_handler","symbol":"exception_handler","correct":"from drf_standardized_errors.handler import exception_handler"},{"symbol":"DRFStandardizedErrorsExceptionHandler","correct":"from drf_standardized_errors.handler import DRFStandardizedErrorsExceptionHandler"}],"quickstart":{"code":"# settings.py\nREST_FRAMEWORK = {\n    \"EXCEPTION_HANDLER\": \"drf_standardized_errors.handler.exception_handler\"\n}","lang":"python","description":"To enable standardized error handling, configure `REST_FRAMEWORK['EXCEPTION_HANDLER']` in your Django settings to point to the library's exception handler."},"warnings":[{"fix":"To revert to the old behavior or customize the generic message, create a custom exception handler class inheriting from `drf_standardized_errors.handler.DRFStandardizedErrorsExceptionHandler` and override `get_fallback_error_message` or `get_generic_error_response_data`.","message":"As of v0.15.0, unhandled exceptions now return a generic error message by default to prevent sensitive data leaks. This changes the previous behavior of exposing the raw exception message.","severity":"breaking","affected_versions":">=0.15.0"},{"fix":"Update your `SPECTACULAR_SETTINGS` to use `drf_standardized_errors.openapi_serializers.ValidationErrorEnum.choices` and `drf_standardized_errors.openapi_serializers.ClientErrorEnum.choices`.","message":"If using `drf-spectacular` (versions 0.27.0 or newer), the `SPECTACULAR_SETTINGS[\"ENUM_NAME_OVERRIDES\"]` entries for 'ValidationErrorEnum' and 'ClientErrorEnum' must reference `choices` instead of `values`.","severity":"breaking","affected_versions":">=0.13.0 (when using `drf-spectacular` >=0.27.0)"},{"fix":"Ensure the `EXCEPTION_HANDLER` setting precisely matches `\"drf_standardized_errors.handler.exception_handler\"`.","message":"Improper configuration of `REST_FRAMEWORK['EXCEPTION_HANDLER']` in `settings.py` will prevent `drf-standardized-errors` from taking effect, resulting in default DRF error responses.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always check the `drf-standardized-errors` release notes or documentation for required `drf-spectacular` versions and upgrade `drf-spectacular` accordingly if experiencing schema generation issues.","message":"Compatibility with `drf-spectacular` for OpenAPI schema generation features is often tied to specific `drf-spectacular` versions. Refer to the release notes for precise version requirements to ensure correct schema generation (e.g., v0.14.0 enforces `drf-spectacular >=0.27`).","severity":"gotcha","affected_versions":"All versions using `drf-spectacular` integration"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}