Commit 8ae753d2 authored by Abhilash Raj's avatar Abhilash Raj

Merge branch 'error-msg' into 'master'

Decode json response correctly to set exception message.

See merge request !102
parents 64ea00a2 e64196dc
Pipeline #57708306 passed with stage
in 5 minutes and 38 seconds
......@@ -98,8 +98,18 @@ class Connection:
# If we did not get a 2xx status code, make this look like a
# urllib2 exception, for backward compatibility.
if response.status_code // 100 != 2:
try:
err = response.json()
# If this fails, a ValueError is raised. It means either
# the response is malformed JSON or None.
error_msg = err['description']
# This can fail if the error message does not container
# description field.
except (KeyError, ValueError):
error_msg = response.text
raise HTTPError(url, response.status_code,
response.content, response, None)
error_msg, response, None)
if len(response.content) == 0:
return response, None
return response, response.json()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment