Skip to content

Commit 5717bdc

Browse files
authored
Catch the base OAuth2Error error, not a custom one (#10082)
* Catch the base OAuth2Error error, not a custom one * Catch error we actually want :)
1 parent 3c909b4 commit 5717bdc

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

readthedocs/oauth/services/github.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
99
from django.conf import settings
1010
from django.urls import reverse
11-
from oauthlib.oauth2.rfc6749.errors import CustomOAuth2Error
11+
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError
1212
from requests.exceptions import RequestException
1313

1414
from readthedocs.api.v2.client import api
@@ -516,9 +516,7 @@ def send_build_status(self, build, commit, state):
516516
# Catch exceptions with request or deserializing JSON
517517
except (RequestException, ValueError):
518518
log.exception('GitHub commit status creation failed for project.')
519-
except CustomOAuth2Error as e:
520-
if e.error != "invalid_grant":
521-
raise
519+
except InvalidGrantError:
522520
log.info("Invalid GitHub grant for user.", exc_info=True)
523521

524522
return False

readthedocs/oauth/services/gitlab.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from allauth.socialaccount.providers.gitlab.views import GitLabOAuth2Adapter
99
from django.conf import settings
1010
from django.urls import reverse
11-
from oauthlib.oauth2.rfc6749.errors import CustomOAuth2Error
11+
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError
1212
from requests.exceptions import RequestException
1313

1414
from readthedocs.builds import utils as build_utils
@@ -602,9 +602,7 @@ def send_build_status(self, build, commit, state):
602602
'GitLab commit status creation failed.',
603603
debug_data=debug_data,
604604
)
605-
except CustomOAuth2Error as e:
606-
if e.error != "invalid_grant":
607-
raise
605+
except InvalidGrantError:
608606
log.info("Invalid GitLab grant for user.", exc_info=True)
609607

610608
return False

0 commit comments

Comments
 (0)