meringue.api.handlers ¤
exception_handler ¤
Error handler returning message and error code pairs.
The handler is a wrapper over the standard handler rest_framework.views.exception_handler
.
Source code in meringue/api/handlers.py
def exception_handler(exc, context):
"""
Error handler returning message and error code pairs.
The handler is a wrapper over the standard handler `rest_framework.views.exception_handler`.
"""
response = views.exception_handler(exc, context)
if response is None:
return response
if isinstance(exc, (Http404, PermissionDenied)):
# django Http404 and PermissionDenied errors are substituted for drf errors,
# in `rest_framework.views.exception_handler` method.
response.data = render_error_details(response.data["detail"])
elif DetailDictMixin and isinstance(exc, DetailDictMixin):
response.data = render_error_details(exc)
elif isinstance(exc, exceptions.APIException):
response.data = render_error_details(exc.detail)
return response