All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog.
- Add support for python 3.14
- Set the minimum version of drf-spectacular to 0.29.0
- Account for the
formatquery parameter raising 404 errors when generating the API schema for error responses. This will result in any project using the default value forREST_FRAMEWORK["URL_FORMAT_OVERRIDE"]"showing 404 errors for every operation. That's because DRF enables theformatquery parameter in every endpoint by default. If you don't need theformatquery parameter for content negotiation, you can disable it with by setting"URL_FORMAT_OVERRIDE"toNonein DRF settings. Refer to DRF docs for more information.
- add support for python 3.13
- add support for django 5.2
- add support for DRF 3.16
- Unhandled exceptions now return a generic error message by default. This avoids unintentionally leaking
sensitive data included in the exception message. To revert to the old behavior or change the default error
message:
- create a custom exception handler class
from rest_framework.exceptions import APIException from drf_standardized_errors.handler import ExceptionHandler class MyExceptionHandler(ExceptionHandler): def convert_unhandled_exceptions(self, exc: Exception) -> APIException: if not isinstance(exc, APIException): # `return APIException(detail=str(exc))` restores the old behavior return APIException(detail="New error message") else: return exc
- Then, update the settings to point to your exception handler class
DRF_STANDARDIZED_ERRORS = { # ... "EXCEPTION_HANDLER_CLASS": "path.to.MyExceptionHandler" }
- create a custom exception handler class
- set minimum version of drf-spectacular to 0.27.1
drf_standardized_errors.types.ErrorTypeis now the following type hintfrom typing import Literal ErrorType = Literal["validation_error", "client_error", "server_error"]
ErrorTypewas previously an enum. If you referenced its members in your code, make sure to replace their use cases with the newly added constants:from drf_standardized_errors.types import VALIDATION_ERROR, CLIENT_ERROR, SERVER_ERROR ErrorType.VALIDATION_ERROR --> VALIDATION_ERROR ErrorType.CLIENT_ERROR --> CLIENT_ERROR ErrorType.SERVER_ERROR --> SERVER_ERROR
- declare support for django 5.1
- stop ignoring exceptions with detail as an empty string when returning api errors.
- declare support for DRF 3.15
- enforce support of only drf-spectacular 0.27 and newer in pyproject.toml
- ensure examples from
@extend_schema_serializerare not ignored when adding error response examples - show default error response examples only when the corresponding status code is allowed
- add
"null"to the error code enum ofnon_field_errorsvalidation errors
- If you're using drf-spectacular 0.27.0 or newer, update
ENUM_NAME_OVERRIDESentries to referencechoicesrather thanvalues. The list of overrides specific to this package should become like this:
SPECTACULAR_SETTINGS = {
# other settings
"ENUM_NAME_OVERRIDES": {
"ValidationErrorEnum": "drf_standardized_errors.openapi_serializers.ValidationErrorEnum.choices",
"ClientErrorEnum": "drf_standardized_errors.openapi_serializers.ClientErrorEnum.choices",
"ServerErrorEnum": "drf_standardized_errors.openapi_serializers.ServerErrorEnum.choices",
"ErrorCode401Enum": "drf_standardized_errors.openapi_serializers.ErrorCode401Enum.choices",
"ErrorCode403Enum": "drf_standardized_errors.openapi_serializers.ErrorCode403Enum.choices",
"ErrorCode404Enum": "drf_standardized_errors.openapi_serializers.ErrorCode404Enum.choices",
"ErrorCode405Enum": "drf_standardized_errors.openapi_serializers.ErrorCode405Enum.choices",
"ErrorCode406Enum": "drf_standardized_errors.openapi_serializers.ErrorCode406Enum.choices",
"ErrorCode415Enum": "drf_standardized_errors.openapi_serializers.ErrorCode415Enum.choices",
"ErrorCode429Enum": "drf_standardized_errors.openapi_serializers.ErrorCode429Enum.choices",
"ErrorCode500Enum": "drf_standardized_errors.openapi_serializers.ErrorCode500Enum.choices",
# other overrides
},
}- add compatibility with drf-spectacular 0.27.x
- add support for django 5.0
- Ensure accurate traceback inclusion in 500 error emails sent to ADMINS by capturing the original exception information using
self.exc. This fixes the issue where tracebacks were previously showing as None fordjango version >= 4.1. - Handle error responses with +1000 errors
- declare support for type checking
- add support for django 4.2
- add support for python 3.12
- Avoid calling
AutoSchema.get_request_serializerwhen inspecting a get operation for possible error responses.
- allow adding extra validation errors on an operation-basis using the new
@extend_validation_errorsdecorator. You can find more information about that in the documentation.
- use
model._default_managerinstead ofmodel.objects. - Don't generate error responses for OpenAPI callbacks.
- Make
_should_add_http403_error_responsecheck if permission isIsAuthenticatedandAllowAnyviatypeinstead ofisinstance - Don't collect error codes from nested
read_onlyfields
- account for specifying the request serializer as a basic type (like
OpenApiTypes.STR) or as aPolymorphicProxySerializerusing@extend_schema(request=...)when determining error codes for validation errors.
- add support for python 3.11
- When a custom validator class defines a
codeattribute, add it to the list of error codes of raised by the corresponding field. - add support for DRF 3.14
- generate the mapping for discriminator fields properly instead of showing a "null" value in the generated schema (#12).
- add support for automatically generating error responses schema with drf-spectacular. Check out the corresponding documentation page to know more about the integration with drf-spectacular.
- add support for django 4.1
- Removed all imports from
drf_standardized_errors.__init__.py. This avoids facing theAppRegistryNotReadyerror in certain situations (fixes #7). This change only affects where functions/classes are imported from, there are no changes to how they work. To upgrade to this version, you need to:- Update the
"EXCEPTION_HANDLER"setting inREST_FRAMEWORKto"drf_standardized_errors.handler.exception_handler". - If you imported the exception handler directly, make sure the import looks like this
from drf_standardized_errors.handler import exception_handler. - If you imported the exception handler class, make sure the import looks like this
from drf_standardized_errors.handler import ExceptionHandler. - If you imported the exception formatter class, make sure the import looks like this
from drf_standardized_errors.formatter import ExceptionFormatter.
- Update the
- disable tag creation by the "create GitHub release" action since it is already created by tbump
- add write permission to create release action, so it can push release notes to GitHub
- fix license badge link so it works on PyPI
- Build the documentation automatically on every commit to the main branch. The docs are hosted on readthedocs.
- Add package metadata
- add a GitHub workflow to create a GitHub release when a new tag is pushed
- add a GitHub workflow to run tests on every push and pull request
- add test coverage
- Common error response format for DRF-based APIs
- Easily customize the error response format.
- Handle error responses for list serializers and nested serializers.
- Add documentation
- Add tests
- Automate release steps