Skip to content

Commit

Permalink
Fail gracefully on account creation timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
jimchamp committed Dec 5, 2024
1 parent fc975df commit 332acb7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
29 changes: 19 additions & 10 deletions openlibrary/accounts/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,16 +665,22 @@ def create(
_screenname = screenname
attempt = 0
while True:
response = cls.xauth(
'create',
email=email,
password=password,
screenname=_screenname,
notifications=notifications,
test=test,
verified=verified,
service='openlibrary',
)
try:
response = cls.xauth(
'create',
email=email,
password=password,
screenname=_screenname,
notifications=notifications,
test=test,
verified=verified,
service='openlibrary',
)
except requests.HTTPError as e:
status_code = e.response.status_code
if status_code == 504:
raise OLAuthenticationError("request_timeout")
raise OLAuthenticationError("undefined_error")

if response.get('success'):
ia_account = cls.get(email=email)
Expand Down Expand Up @@ -723,6 +729,9 @@ def xauth(cls, op, test=None, s3_key=None, s3_secret=None, xauth_url=None, **dat
params['developer'] = test

response = requests.post(url, params=params, json=data)
if response.status_code == 504 and op == "create":
response.raise_for_status()

try:
# This API should always return json, even on error (Unless
# the server is down or something :P)
Expand Down
3 changes: 3 additions & 0 deletions openlibrary/plugins/upstream/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def get_login_error(error_key):
"invalid_s3keys": _(
'Login attempted with invalid Internet Archive s3 credentials.'
),
"request_timeout": _(
"Servers are experiencing unusually high traffic, please try again later or email [email protected] for help."
),
"undefined_error": _('A problem occurred and we were unable to log you in'),
}
return LOGIN_ERRORS[error_key]
Expand Down

0 comments on commit 332acb7

Please sign in to comment.