Skip to content

Commit 0bc7e81

Browse files
authored
Logging: avoid logging invalid_grant error in Sentry (#10022)
* Logging: avoid logging `invalid_grant` error in Sentry This is a known error and it happens because the user revoked the our grant from GitHub/GitLab UI. This commit handles this error and avoids sending it to Sentry. * Logging: exc_info=True
1 parent 0622429 commit 0bc7e81

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

readthedocs/oauth/services/github.py

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +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
1112
from requests.exceptions import RequestException
1213

1314
from readthedocs.api.v2.client import api
@@ -515,6 +516,10 @@ def send_build_status(self, build, commit, state):
515516
# Catch exceptions with request or deserializing JSON
516517
except (RequestException, ValueError):
517518
log.exception('GitHub commit status creation failed for project.')
519+
except CustomOAuth2Error as e:
520+
if e.error != "invalid_grant":
521+
raise
522+
log.info("Invalid GitHub grant for user.", exc_info=True)
518523

519524
return False
520525

readthedocs/oauth/services/gitlab.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +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
1112
from requests.exceptions import RequestException
1213

1314
from readthedocs.builds import utils as build_utils
@@ -601,4 +602,9 @@ def send_build_status(self, build, commit, state):
601602
'GitLab commit status creation failed.',
602603
debug_data=debug_data,
603604
)
604-
return False
605+
except CustomOAuth2Error as e:
606+
if e.error != "invalid_grant":
607+
raise
608+
log.info("Invalid GitLab grant for user.", exc_info=True)
609+
610+
return False

0 commit comments

Comments
 (0)