def custom_exception_handler(exc, context):
"""
Custom exception handler for rest api views
"""
# Call REST framework's default exception handler first,
# to get the standard error response.
log.exception("An exception was intercepted by custom_exception_handler")
response = exception_handler(exc, context)
# if it is handled, just return the response
if response is not None:
return response
# Otherwise format the exception only in specific cases
if isinstance(exc, ImproperlyConfigured):
# send the exception to Sentry anyway
client.captureException()
formatted_exception_string = "{0}: {1}".format(type(exc).__name__, str(exc))
return Response(
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
data=[formatted_exception_string]
)
评论列表
文章目录