Skip to content

Commit 0737da0

Browse files
committed
Capture OAuthError in TwitterLoginSerializer
1 parent 86a487f commit 0737da0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

rest_auth/social_serializers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from django.conf import settings
22
from django.http import HttpRequest
33
from rest_framework import serializers
4-
from requests.exceptions import HTTPError
54
# Import is needed only if we are using social login, in which
65
# case the allauth.socialaccount will be declared
76
if 'allauth.socialaccount' in settings.INSTALLED_APPS:
87
from allauth.socialaccount.helpers import complete_social_login
98
from allauth.socialaccount.models import SocialToken
9+
from allauth.socialaccount.providers.oauth.client import OAuthError
1010

1111

1212
class TwitterLoginSerializer(serializers.Serializer):
@@ -65,8 +65,8 @@ def validate(self, attrs):
6565
try:
6666
login = self.get_social_login(adapter, app, token, access_token)
6767
complete_social_login(request, login)
68-
except HTTPError:
69-
raise serializers.ValidationError('Incorrect value')
68+
except OAuthError as e:
69+
raise serializers.ValidationError(str(e))
7070

7171
if not login.is_existing:
7272
login.lookup()

0 commit comments

Comments
 (0)