Skip to content

Releases: ghazi-git/drf-standardized-errors

Release v0.15.0

09 Jun 07:48
Compare
Choose a tag to compare

Added

  • add support for python 3.13
  • add support for django 5.2
  • add support for DRF 3.16

Changed (backward-incompatible)

  • 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"
      }
  • set minimum version of drf-spectacular to 0.27.1
  • drf_standardized_errors.types.ErrorType is now the following type hint
    from typing import Literal
    ErrorType = Literal["validation_error", "client_error", "server_error"]
    ErrorType was 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
    

Release v0.14.1

10 Aug 16:46
Compare
Choose a tag to compare

Added

  • declare support for django 5.1

Fixed

  • stop ignoring exceptions with detail as an empty string when returning api errors.

Release v0.14.0

19 Jun 22:16
Compare
Choose a tag to compare

Added

  • declare support for DRF 3.15

Fixed

  • enforce support of only drf-spectacular 0.27 and newer in pyproject.toml
  • ensure examples from @extend_schema_serializer are 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 of non_field_errors validation errors

Release v0.13.0

28 Feb 19:22
Compare
Choose a tag to compare

Changed

  • If you're using drf-spectacular 0.27.0 or newer, update ENUM_NAME_OVERRIDES entries to reference choices
    rather than values. 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
    },
}

Added

  • add compatibility with drf-spectacular 0.27.x
  • add support for django 5.0

Fixed

  • 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 for django version >= 4.1.
  • Handle error responses with +1000 errors

Release v0.12.6

25 Oct 17:04
Compare
Choose a tag to compare

Added

  • declare support for type checking
  • add support for django 4.2
  • add support for python 3.12

Fixed

  • Avoid calling AutoSchema.get_request_serializer when inspecting a get operation for possible error responses.

Release v0.12.5

14 Jan 09:13
Compare
Choose a tag to compare

Added

Fixed

  • use model._default_manager instead of model.objects.
  • Don't generate error responses for OpenAPI callbacks.
  • Make _should_add_http403_error_response check if permission is IsAuthenticated and AllowAny via type instead of isinstance
  • Don't collect error codes from nested read_only fields

Release v0.12.4

11 Dec 10:42
Compare
Choose a tag to compare

Fixed

  • account for specifying the request serializer as a basic type (like OpenApiTypes.STR) or as a
    PolymorphicProxySerializer using @extend_schema(request=...) when determining error codes for validation errors.

Release v0.12.3

13 Nov 10:46
Compare
Choose a tag to compare

Added

  • add support for python 3.11

Release v0.12.2

25 Sep 07:26
Compare
Choose a tag to compare

Added

  • When a custom validator class defines a code attribute, add it to the list of error codes raised by
    the corresponding field.
  • add support for DRF 3.14

Release v0.12.1

03 Sep 09:17
Compare
Choose a tag to compare

Fixed

  • generate the mapping for discriminator fields properly instead of showing a "null" value in the generated schema (#12).