@@ -46,6 +46,7 @@ def __init__(self, resp, content, uri=None):
4646 raise TypeError ("HTTP content should be bytes" )
4747 self .content = content
4848 self .uri = uri
49+ self .error_details = ''
4950
5051 def _get_reason (self ):
5152 """Calculate the reason for the error from the response content."""
@@ -54,17 +55,25 @@ def _get_reason(self):
5455 data = json .loads (self .content .decode ('utf-8' ))
5556 if isinstance (data , dict ):
5657 reason = data ['error' ]['message' ]
58+ if 'details' in data ['error' ]:
59+ self .error_details = data ['error' ]['details' ]
5760 elif isinstance (data , list ) and len (data ) > 0 :
5861 first_error = data [0 ]
5962 reason = first_error ['error' ]['message' ]
63+ if 'details' in first_error ['error' ]:
64+ self .error_details = first_error ['error' ]['details' ]
6065 except (ValueError , KeyError , TypeError ):
6166 pass
6267 if reason is None :
6368 reason = ''
6469 return reason
6570
6671 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 :
6877 return '<HttpError %s when requesting %s returned "%s">' % (
6978 self .resp .status , self .uri , self ._get_reason ().strip ())
7079 else :
0 commit comments