Skip to content

Commit 3189a5c

Browse files
committed
Merge pull request #187 from marsam/master
Capture OAuthError in TwitterLoginSerializer
2 parents 5e4d85b + 0737da0 commit 3189a5c

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

rest_auth/registration/serializers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@
1515
from requests.exceptions import HTTPError
1616
# Import is needed only if we are using social login, in which
1717
# case the allauth.socialaccount will be declared
18-
1918
if 'allauth.socialaccount' in settings.INSTALLED_APPS:
20-
try:
21-
from allauth.socialaccount.helpers import complete_social_login
22-
except ImportError:
23-
pass
19+
from allauth.socialaccount.helpers import complete_social_login
2420

2521

2622
class SocialLoginSerializer(serializers.Serializer):

rest_auth/social_serializers.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1+
from django.conf import settings
12
from django.http import HttpRequest
23
from rest_framework import serializers
3-
from requests.exceptions import HTTPError
44
# Import is needed only if we are using social login, in which
55
# case the allauth.socialaccount will be declared
6-
try:
6+
if 'allauth.socialaccount' in settings.INSTALLED_APPS:
77
from allauth.socialaccount.helpers import complete_social_login
8-
except ImportError:
9-
pass
10-
11-
from allauth.socialaccount.models import SocialToken
8+
from allauth.socialaccount.models import SocialToken
9+
from allauth.socialaccount.providers.oauth.client import OAuthError
1210

1311

1412
class TwitterLoginSerializer(serializers.Serializer):
@@ -67,8 +65,8 @@ def validate(self, attrs):
6765
try:
6866
login = self.get_social_login(adapter, app, token, access_token)
6967
complete_social_login(request, login)
70-
except HTTPError:
71-
raise serializers.ValidationError('Incorrect value')
68+
except OAuthError as e:
69+
raise serializers.ValidationError(str(e))
7270

7371
if not login.is_existing:
7472
login.lookup()

0 commit comments

Comments
 (0)