@@ -112,8 +112,8 @@ def _exception_for_error(
112112 if 400 <= status < 500 :
113113 return self ._exception_for_4xx_status (status , content_type , body , uri )
114114 if 500 <= status < 600 :
115- return self ._exception_for_5xx_status (status , uri )
116- return self ._exception_for_non_200_status (status , uri )
115+ return self ._exception_for_5xx_status (status , uri , body )
116+ return self ._exception_for_non_200_status (status , uri , body )
117117
118118 def _exception_for_4xx_status (
119119 self , status : int , content_type : str , body : str , uri : str
@@ -123,13 +123,15 @@ def _exception_for_4xx_status(
123123 "Received a %(status)i error for %(uri)s " "with no body." % locals (),
124124 status ,
125125 uri ,
126+ body ,
126127 )
127128 if content_type .find ("json" ) == - 1 :
128129 return HTTPError (
129130 "Received a %i for %s with the following "
130131 "body: %s" % (status , uri , str (content_type )),
131132 status ,
132133 uri ,
134+ body ,
133135 )
134136 try :
135137 decoded_body = json .loads (body )
@@ -139,6 +141,7 @@ def _exception_for_4xx_status(
139141 " not include the expected JSON body: " % locals () + ", " .join (ex .args ),
140142 status ,
141143 uri ,
144+ body ,
142145 )
143146 else :
144147 if "code" in decoded_body and "error" in decoded_body :
@@ -149,6 +152,7 @@ def _exception_for_4xx_status(
149152 "Response contains JSON but it does not specify " "code or error keys" ,
150153 status ,
151154 uri ,
155+ body ,
152156 )
153157
154158 @staticmethod
@@ -180,20 +184,26 @@ def _exception_for_web_service_error(
180184 return InvalidRequestError (message , code , status , uri )
181185
182186 @staticmethod
183- def _exception_for_5xx_status (status : int , uri : str ) -> HTTPError :
187+ def _exception_for_5xx_status (
188+ status : int , uri : str , body : Optional [str ]
189+ ) -> HTTPError :
184190 return HTTPError (
185191 "Received a server error (%(status)i) for " "%(uri)s" % locals (),
186192 status ,
187193 uri ,
194+ body ,
188195 )
189196
190197 @staticmethod
191- def _exception_for_non_200_status (status : int , uri : str ) -> HTTPError :
198+ def _exception_for_non_200_status (
199+ status : int , uri : str , body : Optional [str ]
200+ ) -> HTTPError :
192201 return HTTPError (
193202 "Received a very surprising HTTP status "
194203 "(%(status)i) for %(uri)s" % locals (),
195204 status ,
196205 uri ,
206+ body ,
197207 )
198208
199209
0 commit comments