@@ -136,8 +136,8 @@ def _exception_for_error(
136136 if 400 <= status < 500 :
137137 return self ._exception_for_4xx_status (status , content_type , body , uri )
138138 if 500 <= status < 600 :
139- return self ._exception_for_5xx_status (status , uri )
140- return self ._exception_for_unexpected_status (status , uri )
139+ return self ._exception_for_5xx_status (status , body , uri )
140+ return self ._exception_for_unexpected_status (status , body , uri )
141141
142142 def _exception_for_4xx_status (
143143 self , status : int , content_type : str , body : str , uri : str
@@ -151,13 +151,14 @@ def _exception_for_4xx_status(
151151 """Returns exception for error responses with 4xx status codes."""
152152 if not body :
153153 return HTTPError (
154- "Received a {0} error with no body" .format (status ), status , uri
154+ "Received a {0} error with no body" .format (status ), status , uri , body
155155 )
156156 if content_type .find ("json" ) == - 1 :
157157 return HTTPError (
158158 "Received a {0} with the following " "body: {1}" .format (status , body ),
159159 status ,
160160 uri ,
161+ body ,
161162 )
162163 try :
163164 decoded_body = json .loads (body )
@@ -169,6 +170,7 @@ def _exception_for_4xx_status(
169170 ),
170171 status ,
171172 uri ,
173+ body ,
172174 )
173175 else :
174176 if "code" in decoded_body and "error" in decoded_body :
@@ -180,6 +182,7 @@ def _exception_for_4xx_status(
180182 " or error keys: {0}" .format (body ),
181183 status ,
182184 uri ,
185+ body ,
183186 )
184187
185188 @staticmethod
@@ -207,21 +210,31 @@ def _exception_for_web_service_error(
207210 return InvalidRequestError (message , code , status , uri )
208211
209212 @staticmethod
210- def _exception_for_5xx_status (status : int , uri : str ) -> HTTPError :
213+ def _exception_for_5xx_status (
214+ status : int ,
215+ body : Optional [str ],
216+ uri : str ,
217+ ) -> HTTPError :
211218 """Returns exception for error response with 5xx status codes."""
212219 return HTTPError (
213220 u"Received a server error ({0}) for " u"{1}" .format (status , uri ),
214221 status ,
215222 uri ,
223+ body ,
216224 )
217225
218226 @staticmethod
219- def _exception_for_unexpected_status (status : int , uri : str ) -> HTTPError :
227+ def _exception_for_unexpected_status (
228+ status : int ,
229+ body : Optional [str ],
230+ uri : str ,
231+ ) -> HTTPError :
220232 """Returns exception for responses with unexpected status codes."""
221233 return HTTPError (
222234 u"Received an unexpected HTTP status " u"({0}) for {1}" .format (status , uri ),
223235 status ,
224236 uri ,
237+ body ,
225238 )
226239
227240
0 commit comments