@@ -271,7 +271,7 @@ def _handle_retry_and_timeout(self, endpoint, request, signer):
271271 retryable = self ._retry_policy .should_retry (retry_policy_context )
272272 if retryable & RetryCondition .NO_RETRY :
273273 break
274- logger .debug ("Retry needed Request:%s Retries :%d" ,
274+ logger .debug ("Retry needed. Request:%s Retries :%d" ,
275275 request .get_action_name (), retries )
276276 retry_policy_context .retryable = retryable
277277 time_to_sleep = self ._retry_policy .compute_delay_before_next_retry (retry_policy_context )
@@ -287,19 +287,20 @@ def _handle_single_request(self, endpoint, request, timeout, signer):
287287 http_response = self ._make_http_response (endpoint , request , timeout , signer )
288288 params = copy .deepcopy (request .get_query_params ())
289289 params .pop ('AccessKeyId' , None )
290- logger .debug ('Request params are %s' , str (params ))
290+ logger .debug ('Request received. Product:%s Endpoint:%s Params: %s' ,
291+ request .get_product (), endpoint , str (params ))
291292
292293 # Do the actual network thing
293294 try :
294295 status , headers , body = http_response .get_response_object ()
295296 except IOError as e :
296- logger .error ("HttpError occurred Host:%s SDK-Version:%s" ,
297- endpoint , aliyunsdkcore .__version__ )
298297
299298 exception = ClientException (error_code .SDK_HTTP_ERROR , str (e ))
299+ logger .error ("HttpError occurred. Host:%s SDK-Version:%s ClientException:%s" ,
300+ endpoint , aliyunsdkcore .__version__ , str (exception ))
300301 return None , None , None , exception
301302
302- exception = self ._get_server_exception (status , body )
303+ exception = self ._get_server_exception (status , body , endpoint )
303304 return status , headers , body , exception
304305
305306 @staticmethod
@@ -315,11 +316,11 @@ def _parse_error_info_from_response_body(response_body):
315316 error_message_to_return = body_obj ['Message' ]
316317 except ValueError :
317318 # failed to parse body as json format
318- logger .warning ('Failed to parse Response:%s as json format.' , response_body )
319+ logger .warning ('Failed to parse response as json format. Response:%s ' , response_body )
319320
320321 return error_code_to_return , error_message_to_return
321322
322- def _get_server_exception (self , http_status , response_body ):
323+ def _get_server_exception (self , http_status , response_body , endpoint ):
323324 request_id = None
324325
325326 try :
@@ -328,29 +329,35 @@ def _get_server_exception(self, http_status, response_body):
328329 except (ValueError , TypeError , AttributeError ):
329330 # in case the response body is not a json string, return the raw
330331 # data instead
331- logger .warning ('Failed to parse Response:%s as json format.' , response_body )
332+ logger .warning ('Failed to parse response as json format. Response:%s ' , response_body )
332333
333334 if http_status < codes .OK or http_status >= codes .MULTIPLE_CHOICES :
334335
335336 server_error_code , server_error_message = self ._parse_error_info_from_response_body (
336337 response_body .decode ('utf-8' ))
337- return ServerException (
338+
339+ exception = ServerException (
338340 server_error_code ,
339341 server_error_message ,
340342 http_status = http_status ,
341343 request_id = request_id )
342344
345+ logger .error ("ServerException occurred. Host:%s SDK-Version:%s ServerException:%s" ,
346+ endpoint , aliyunsdkcore .__version__ , str (exception ))
347+
348+ return exception
349+
343350 def do_action_with_exception (self , acs_request ):
344351
345352 # set server response format as json, because this function will
346353 # parse the response so which format doesn't matter
347354 acs_request .set_accept_format ('JSON' )
348-
349355 status , headers , body , exception = self ._implementation_of_do_action (acs_request )
350356
351357 if exception :
352358 raise exception
353-
359+ logger .debug ('Response received. Product:%s Response-body: %s' ,
360+ acs_request .get_product (), body )
354361 return body
355362
356363 def _resolve_endpoint (self , request ):
@@ -396,4 +403,3 @@ def set_file_logger(self, path, log_level=logging.INFO, logger_name='aliyunsdkco
396403 formatter = logging .Formatter (self .LOG_FORMAT )
397404 fh .setFormatter (formatter )
398405 log .addHandler (fh )
399-
0 commit comments