Skip to content

Commit

Permalink
fix(logging): Auth exceptions are now sent in response (#131)
Browse files Browse the repository at this point in the history
This gives exception right in data of response. Previously, it was just empty string if `AuthException` was raised.
  • Loading branch information
jd-solanki committed Jan 17, 2021
1 parent 60da83c commit c326c50
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rest_social_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,17 @@ def get_provider_name(self, input_data):
return input_data.get('provider')

def respond_error(self, error):
message = error if isinstance(error, str) else ''
if isinstance(error, Exception):
if not isinstance(error, AuthException) or LOG_AUTH_EXCEPTIONS:
self.log_exception(error)
try:
message = error.response.json()['error']['message']
except KeyError:
pass
else:
logger.error(error)
return Response(status=status.HTTP_400_BAD_REQUEST)
return Response(data=message, status=status.HTTP_400_BAD_REQUEST)

def log_exception(self, error):
err_msg = error.args[0] if error.args else ''
Expand Down

0 comments on commit c326c50

Please sign in to comment.