Skip to content

Commit

Permalink
Merge pull request #10378 from jimchamp/log-acct-creation-response-on…
Browse files Browse the repository at this point in the history
…-failure

Expose account creation `xauthn` response to Sentry
  • Loading branch information
mekarpeles authored Jan 27, 2025
2 parents bd254c4 + 9bd5510 commit ffc95cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion openlibrary/accounts/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,9 @@ def create(
return ia_account

elif 'screenname' not in response.get('values', {}):
raise OLAuthenticationError('undefined_error')
error = OLAuthenticationError('undefined_error')
error.response = response
raise error

elif attempt >= retries:
e = OLAuthenticationError('username_registered')
Expand Down
3 changes: 2 additions & 1 deletion openlibrary/plugins/upstream/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ def POST(self):
from openlibrary.plugins.openlibrary.sentry import sentry

if sentry.enabled:
sentry.capture_exception(e)
extra = {'response': e.response} if hasattr(e, 'response') else None
sentry.capture_exception(e, extras=extra)

return render['account/create'](f)

Expand Down
5 changes: 4 additions & 1 deletion openlibrary/utils/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ def capture_exception_webpy(self):
scope.add_event_processor(add_web_ctx_to_event)
sentry_sdk.capture_exception()

def capture_exception(self, ex):
def capture_exception(self, ex, extras: dict | None = None):
with sentry_sdk.push_scope() as scope:
if extras:
for key, value in extras.items():
scope.set_extra(key, value)
scope.add_event_processor(add_web_ctx_to_event)
sentry_sdk.capture_exception(ex)

Expand Down

0 comments on commit ffc95cf

Please sign in to comment.