diff --git a/readthedocs/oauth/services/github.py b/readthedocs/oauth/services/github.py index e95a2f7d4e8..a46af32741c 100644 --- a/readthedocs/oauth/services/github.py +++ b/readthedocs/oauth/services/github.py @@ -8,6 +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 requests.exceptions import RequestException from readthedocs.api.v2.client import api @@ -515,6 +516,10 @@ 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 + 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 403ace05ee8..25271842b9a 100644 --- a/readthedocs/oauth/services/gitlab.py +++ b/readthedocs/oauth/services/gitlab.py @@ -8,6 +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 requests.exceptions import RequestException from readthedocs.builds import utils as build_utils @@ -601,4 +602,9 @@ def send_build_status(self, build, commit, state): 'GitLab commit status creation failed.', debug_data=debug_data, ) - return False + except CustomOAuth2Error as e: + if e.error != "invalid_grant": + raise + log.info("Invalid GitLab grant for user.", exc_info=True) + + return False