Skip to content
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

Improve handling of error responses from the API #327

Merged
merged 1 commit into from May 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/pylast/__init__.py
Expand Up @@ -932,7 +932,15 @@ def _download_response(self):
raise NetworkError(self.network, e)

try:
response_text = _unicode(conn.getresponse().read())
response = conn.getresponse()
if response.status in [500, 502, 503, 504]:
raise WSError(
self.network,
response.status,
"Connection to the API failed with HTTP code "
+ str(response.status),
)
response_text = _unicode(response.read())
except Exception as e:
raise MalformedResponseError(self.network, e)

Expand Down