Skip to content

Commit d0a9b51

Browse files
Fail gracefully on account creation timeout (#10121)
* Fail gracefully on account creation timeout --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 139c754 commit d0a9b51

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

openlibrary/accounts/model.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -665,16 +665,22 @@ def create(
665665
_screenname = screenname
666666
attempt = 0
667667
while True:
668-
response = cls.xauth(
669-
'create',
670-
email=email,
671-
password=password,
672-
screenname=_screenname,
673-
notifications=notifications,
674-
test=test,
675-
verified=verified,
676-
service='openlibrary',
677-
)
668+
try:
669+
response = cls.xauth(
670+
'create',
671+
email=email,
672+
password=password,
673+
screenname=_screenname,
674+
notifications=notifications,
675+
test=test,
676+
verified=verified,
677+
service='openlibrary',
678+
)
679+
except requests.HTTPError as err:
680+
status_code = err.response.status_code
681+
if status_code == 504:
682+
raise OLAuthenticationError("request_timeout")
683+
raise OLAuthenticationError("undefined_error")
678684

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

725731
response = requests.post(url, params=params, json=data)
732+
if response.status_code == 504 and op == "create":
733+
response.raise_for_status()
734+
726735
try:
727736
# This API should always return json, even on error (Unless
728737
# the server is down or something :P)

openlibrary/i18n/messages.pot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7715,6 +7715,12 @@ msgstr ""
77157715
msgid "Login attempted with invalid Internet Archive s3 credentials."
77167716
msgstr ""
77177717

7718+
#: account.py
7719+
msgid ""
7720+
"Servers are experiencing unusually high traffic, please try again later "
7721+
"or email openlibrary@archive.org for help."
7722+
msgstr ""
7723+
77187724
#: account.py
77197725
msgid "A problem occurred and we were unable to log you in"
77207726
msgstr ""

openlibrary/plugins/upstream/account.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ def get_login_error(error_key):
9090
"invalid_s3keys": _(
9191
'Login attempted with invalid Internet Archive s3 credentials.'
9292
),
93+
"request_timeout": _(
94+
"Servers are experiencing unusually high traffic, please try again later or email openlibrary@archive.org for help."
95+
),
9396
"undefined_error": _('A problem occurred and we were unable to log you in'),
9497
}
9598
return LOGIN_ERRORS[error_key]

0 commit comments

Comments
 (0)