diff --git a/config/settings.py b/config/settings.py index 306e650..2832561 100644 --- a/config/settings.py +++ b/config/settings.py @@ -86,6 +86,7 @@ "constance", "constance.backends.database", "anymail", + "drf_standardized_errors", ] LOCAL_APPS = [ "apps.api_auth.apps.ApiAuthConfig", @@ -281,8 +282,9 @@ "rest_framework_simplejwt.authentication.JWTAuthentication", "dj_rest_auth.jwt_auth.JWTCookieAuthentication", ], - "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", + "DEFAULT_SCHEMA_CLASS": "drf_standardized_errors.openapi.AutoSchema", "DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"], + "EXCEPTION_HANDLER": "drf_standardized_errors.handler.exception_handler", } # django-cors-headers - https://github.com/adamchainz/django-cors-headers#setup # Enable CORS to all API endpoints. @@ -313,6 +315,20 @@ "SERVE_PERMISSIONS": ["rest_framework.permissions.IsAdminUser"], "SERVE_AUTHENTICATION": ["rest_framework.authentication.SessionAuthentication"], "AUTHENTICATION_WHITELIST": ["rest_framework_simplejwt.authentication.JWTAuthentication"], + "POSTPROCESSING_HOOKS": ["drf_standardized_errors.openapi_hooks.postprocess_schema_enums"], + "ENUM_NAME_OVERRIDES": { + "ValidationErrorEnum": "drf_standardized_errors.openapi_serializers.ValidationErrorEnum.values", + "ClientErrorEnum": "drf_standardized_errors.openapi_serializers.ClientErrorEnum.values", + "ServerErrorEnum": "drf_standardized_errors.openapi_serializers.ServerErrorEnum.values", + "ErrorCode401Enum": "drf_standardized_errors.openapi_serializers.ErrorCode401Enum.values", + "ErrorCode403Enum": "drf_standardized_errors.openapi_serializers.ErrorCode403Enum.values", + "ErrorCode404Enum": "drf_standardized_errors.openapi_serializers.ErrorCode404Enum.values", + "ErrorCode405Enum": "drf_standardized_errors.openapi_serializers.ErrorCode405Enum.values", + "ErrorCode406Enum": "drf_standardized_errors.openapi_serializers.ErrorCode406Enum.values", + "ErrorCode415Enum": "drf_standardized_errors.openapi_serializers.ErrorCode415Enum.values", + "ErrorCode429Enum": "drf_standardized_errors.openapi_serializers.ErrorCode429Enum.values", + "ErrorCode500Enum": "drf_standardized_errors.openapi_serializers.ErrorCode500Enum.values", + }, } # ---------------------------------------------------------- Django Constance ------------------------------------------ diff --git a/requirements.txt b/requirements.txt index da1f665..91980d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,7 @@ django-filter==23.2 Pillow==10.0.1 django-anymail==10.1 drf-spectacular==0.26.4 +drf-standardized-errors[openapi]==0.12.5 # ---------------------------------------------------------- Admin Panel ----------------------------------------------- django-admin-interface==0.26.1