Skip to content

Commit

Permalink
Fail gracefully on account creation timeout (#10121)
Browse files Browse the repository at this point in the history
* Fail gracefully on account creation timeout

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
jimchamp and pre-commit-ci[bot] authored Dec 18, 2024
1 parent 139c754 commit d0a9b51
Show file tree
Hide file tree
Showing 3 changed files with 28 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 err:
status_code = err.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
6 changes: 6 additions & 0 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7715,6 +7715,12 @@ msgstr ""
msgid "Login attempted with invalid Internet Archive s3 credentials."
msgstr ""

#: account.py
msgid ""
"Servers are experiencing unusually high traffic, please try again later "
"or email openlibrary@archive.org for help."
msgstr ""

#: account.py
msgid "A problem occurred and we were unable to log you in"
msgstr ""
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 @@ -90,6 +90,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 openlibrary@archive.org 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 d0a9b51

Please sign in to comment.