Skip to content

Commit

Permalink
Improve how HTTP errors are reported as client errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed May 18, 2023
1 parent 9a1c607 commit 09235dd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions mergin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,17 @@ def _do_request(self, request):
except urllib.error.HTTPError as e:
if e.headers.get("Content-Type", "") == "application/problem+json":
info = json.load(e)
raise ClientError(info.get("detail"))
raise ClientError(e.read().decode("utf-8"))
err_detail = info.get("detail")
else:
err_detail = e.read().decode("utf-8")

error_msg = (
f"HTTP Error: {e.code} {e.reason}\n"
f"URL: {request.get_full_url()}\n"
f"Method: {request.get_method()}\n"
f"Detail: {err_detail}"
)
raise ClientError(error_msg)
except urllib.error.URLError as e:
# e.g. when DNS resolution fails (no internet connection?)
raise ClientError("Error requesting " + request.full_url + ": " + str(e))
Expand Down

0 comments on commit 09235dd

Please # to comment.