diff --git a/readthedocs/oauth/services/github.py b/readthedocs/oauth/services/github.py index a46af32741c..ed44f7cde8c 100644 --- a/readthedocs/oauth/services/github.py +++ b/readthedocs/oauth/services/github.py @@ -8,7 +8,7 @@ from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter from django.conf import settings from django.urls import reverse -from oauthlib.oauth2.rfc6749.errors import CustomOAuth2Error +from oauthlib.oauth2.rfc6749.errors import InvalidGrantError from requests.exceptions import RequestException from readthedocs.api.v2.client import api @@ -516,9 +516,7 @@ def send_build_status(self, build, commit, state): # Catch exceptions with request or deserializing JSON except (RequestException, ValueError): log.exception('GitHub commit status creation failed for project.') - except CustomOAuth2Error as e: - if e.error != "invalid_grant": - raise + except InvalidGrantError: log.info("Invalid GitHub grant for user.", exc_info=True) return False diff --git a/readthedocs/oauth/services/gitlab.py b/readthedocs/oauth/services/gitlab.py index 25271842b9a..95d1f6247c5 100644 --- a/readthedocs/oauth/services/gitlab.py +++ b/readthedocs/oauth/services/gitlab.py @@ -8,7 +8,7 @@ from allauth.socialaccount.providers.gitlab.views import GitLabOAuth2Adapter from django.conf import settings from django.urls import reverse -from oauthlib.oauth2.rfc6749.errors import CustomOAuth2Error +from oauthlib.oauth2.rfc6749.errors import InvalidGrantError from requests.exceptions import RequestException from readthedocs.builds import utils as build_utils @@ -602,9 +602,7 @@ def send_build_status(self, build, commit, state): 'GitLab commit status creation failed.', debug_data=debug_data, ) - except CustomOAuth2Error as e: - if e.error != "invalid_grant": - raise + except InvalidGrantError: log.info("Invalid GitLab grant for user.", exc_info=True) return False