Skip to content

Commit d7abacc

Browse files
authored
OAuth: catch TokenExpiredError exception (#10510)
There is nothing we can do in this case. So, we are logging the exception instead of sending it to Sentry as an error. In the future we could handle this exception differently and communicate these errors to the users so they can re-install Read the Docs app in their GH accounts. Sentry: https://read-the-docs.sentry.io/issues/3526635712/
1 parent 054897e commit d7abacc

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

readthedocs/oauth/services/github.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
88
from django.conf import settings
99
from django.urls import reverse
10-
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError
10+
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError, TokenExpiredError
1111
from requests.exceptions import RequestException
1212

1313
from readthedocs.builds import utils as build_utils
@@ -517,5 +517,7 @@ def send_build_status(self, build, commit, status):
517517
log.exception('GitHub commit status creation failed for project.')
518518
except InvalidGrantError:
519519
log.info("Invalid GitHub grant for user.", exc_info=True)
520+
except TokenExpiredError:
521+
log.info("GitHub token expired for user.", exc_info=True)
520522

521523
return False

readthedocs/oauth/services/gitlab.py

+3-1
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 InvalidGrantError
11+
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError, TokenExpiredError
1212
from requests.exceptions import RequestException
1313

1414
from readthedocs.builds import utils as build_utils
@@ -604,5 +604,7 @@ def send_build_status(self, build, commit, status):
604604
)
605605
except InvalidGrantError:
606606
log.info("Invalid GitLab grant for user.", exc_info=True)
607+
except TokenExpiredError:
608+
log.info("GitLab token expired for user.", exc_info=True)
607609

608610
return False

0 commit comments

Comments
 (0)