Skip to content

Logging: avoid logging invalid_grant error in Sentry #10022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions readthedocs/oauth/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")

return False

Expand Down
8 changes: 7 additions & 1 deletion readthedocs/oauth/services/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")

return False