From 6a28ba076fafec2105ca225a0e2d88a5c0a48221 Mon Sep 17 00:00:00 2001 From: spiritualized Date: Tue, 28 Apr 2020 04:22:31 -0400 Subject: [PATCH] Improve handling of error responses from the API --- src/pylast/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pylast/__init__.py b/src/pylast/__init__.py index 50c1206..8495c58 100644 --- a/src/pylast/__init__.py +++ b/src/pylast/__init__.py @@ -932,7 +932,15 @@ class _Request: 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)