@@ -46,6 +46,7 @@ def __init__(self, resp, content, uri=None):
46
46
raise TypeError ("HTTP content should be bytes" )
47
47
self .content = content
48
48
self .uri = uri
49
+ self .error_details = ''
49
50
50
51
def _get_reason (self ):
51
52
"""Calculate the reason for the error from the response content."""
@@ -54,17 +55,25 @@ def _get_reason(self):
54
55
data = json .loads (self .content .decode ('utf-8' ))
55
56
if isinstance (data , dict ):
56
57
reason = data ['error' ]['message' ]
58
+ if 'details' in data ['error' ]:
59
+ self .error_details = data ['error' ]['details' ]
57
60
elif isinstance (data , list ) and len (data ) > 0 :
58
61
first_error = data [0 ]
59
62
reason = first_error ['error' ]['message' ]
63
+ if 'details' in first_error ['error' ]:
64
+ self .error_details = first_error ['error' ]['details' ]
60
65
except (ValueError , KeyError , TypeError ):
61
66
pass
62
67
if reason is None :
63
68
reason = ''
64
69
return reason
65
70
66
71
def __repr__ (self ):
67
- if self .uri :
72
+ reason = self ._get_reason ()
73
+ if self .error_details :
74
+ return '<HttpError %s when requesting %s returned "%s". Details: "%s">' % \
75
+ (self .resp .status , self .uri , reason .strip (), self .error_details )
76
+ elif self .uri :
68
77
return '<HttpError %s when requesting %s returned "%s">' % (
69
78
self .resp .status , self .uri , self ._get_reason ().strip ())
70
79
else :
0 commit comments