Skip to content

Commit

Permalink
Update exceptionhandler.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sannjayy authored Dec 12, 2024
1 parent 73061ce commit 35ea994
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion utils/exceptionhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,20 @@ def _handle_authentication_error(exc, context, response):
return response


def _handle_generic_error(exc, context, response):
def _handle_generic_error(exc, context, response):
if isinstance(exc, ValidationError):
# Access the `detail` attribute for structured error information
error_detail = exc.detail
if isinstance(error_detail, list) and len(error_detail) > 0 and isinstance(error_detail[0], ErrorDetail):
error_detail = str(error_detail[0])
else:
error_detail = str(error_detail)
else:
# For non-ValidationError exceptions, fallback to string
error_detail = str(exc)

response.data = {
'success': response.status_code in [200, 201],
'detail': error_detail
}
return response

0 comments on commit 35ea994

Please # to comment.