def __init__(self, http_response, response_body=None):
"""Sets the HTTP information in the error.
Args:
http_response: The response from the server, contains error information.
response_body: string (optional) specified if the response has already
been read from the http_response object.
"""
body = response_body or http_response.read()
self.status = http_response.status
self.reason = http_response.reason
self.body = body
self.headers = atom.http_core.get_headers(http_response)
self.error_msg = 'Invalid response %s.' % self.status
try:
json_from_body = simplejson.loads(body)
if isinstance(json_from_body, dict):
self.error_msg = json_from_body.get('error', self.error_msg)
except (ValueError, JSONDecodeError):
pass
评论列表
文章目录