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 ce9c6bf
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions labelbox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,22 @@ 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 response.status_code == 200:
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 response.status_code >= 500 and 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)
Expand Down

0 comments on commit ce9c6bf

Please sign in to comment.