Skip to content

Commit

Permalink
Fix 500 error handling and reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrodsky committed Mar 7, 2024
1 parent edc52dd commit be7dd22
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions labelbox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,26 @@ def convert_value(value):
except Exception as e:
raise labelbox.exceptions.LabelboxError(
"Unknown error during Client.query(): " + str(e), e)
try:
r_json = response.json()
except:
if "upstream connect error or disconnect/reset before headers" \
in response.text:
if 200 <= response.status_code < 300:
try:
r_json = response.json()
except Exception:
raise labelbox.exceptions.LabelboxError(
"Failed to parse response as JSON: %s" % response.text)
else:
if "upstream connect error or disconnect/reset before headers" in response.text:
raise labelbox.exceptions.InternalServerError(
"Connection reset")
elif response.status_code == 502:
error_502 = '502 Bad Gateway'
raise labelbox.exceptions.InternalServerError(error_502)
elif 500 <= response.status_code < 600:
error_500 = f"Internal server http error {response.status_code}"
raise labelbox.exceptions.InternalServerError(error_500)

raise labelbox.exceptions.LabelboxError(
"Failed to parse response as JSON: %s" % response.text)
f"Failed with http status code: {response.status_code}, more info: {response.text}"
)

errors = r_json.get("errors", [])

Expand Down

0 comments on commit be7dd22

Please sign in to comment.