Skip to content

Commit

Permalink
Bug fix: For a javascript ajax call, set the return code instead of d…
Browse files Browse the repository at this point in the history
…efault 200 in error view exception handler (#1637)

* Bug fix: For a javascript ajax call, set the return code instead of default 200 in error view exception handler

* Update error_views.py

* Update error_views.py
  • Loading branch information
liyaqin1 authored May 31, 2024
1 parent 2217ba4 commit c67d381
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion deploy-board/deploy_board/webapp/error_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ def process_exception(self, request, exception):
# Error is displayed as a fragment over related feature area
if request.is_ajax():
ajax_vars = {'success': False, 'error': str(exception)}
return HttpResponse(json.dumps(ajax_vars), content_type='application/javascript')
ret = 500
if isinstance(exception, IllegalArgumentException):
ret = 400
elif isinstance(exception, FailedAuthenticationException):
ret = 401
elif isinstance(exception, NotAuthorizedException):
ret = 403
elif isinstance(exception, NotFoundException):
ret = 404
return HttpResponse(json.dumps(ajax_vars), status=ret, content_type='application/javascript')
else:
# Not authorized
if isinstance(exception, NotAuthorizedException):
Expand Down

0 comments on commit c67d381

Please sign in to comment.