Commit 62c1dc9 1 parent 51d4ced commit 62c1dc9 Copy full SHA for 62c1dc9
File tree 1 file changed +7
-1
lines changed
dj_rest_auth/registration
1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change
1
+ from allauth .socialaccount .providers .oauth2 .client import OAuth2Error
1
2
from django .contrib .auth import get_user_model
2
3
from django .core .exceptions import ValidationError as DjangoValidationError
3
4
from django .http import HttpRequest , HttpResponseBadRequest
@@ -130,7 +131,12 @@ def validate(self, attrs):
130
131
headers = adapter .headers ,
131
132
basic_auth = adapter .basic_auth ,
132
133
)
133
- token = client .get_access_token (code )
134
+ try :
135
+ token = client .get_access_token (code )
136
+ except OAuth2Error as ex :
137
+ raise serializers .ValidationError (
138
+ _ ('Failed to exchange code for access token' )
139
+ ) from ex
134
140
access_token = token ['access_token' ]
135
141
tokens_to_parse = {'access_token' : access_token }
136
142
You can’t perform that action at this time.
0 commit comments