@@ -359,6 +359,7 @@ def send_request(self, method, url, bucket, timeout=30, cos_request=True, ci_req
359
359
kwargs ['verify' ] = False
360
360
if self ._conf ._allow_redirects is not None :
361
361
kwargs ['allow_redirects' ] = self ._conf ._allow_redirects
362
+ exception_logbuf = list () # 记录每次重试的错误日志
362
363
for j in range (self ._retry + 1 ):
363
364
try :
364
365
if j != 0 :
@@ -397,13 +398,16 @@ def send_request(self, method, url, bucket, timeout=30, cos_request=True, ci_req
397
398
else :
398
399
break
399
400
except Exception as e : # 捕获requests抛出的如timeout等客户端错误,转化为客户端错误
400
- logger .exception ('url:%s, retry_time:%d exception:%s' % (url , j , str (e )))
401
+ # 记录每次请求的exception
402
+ exception_log = 'url:%s, retry_time:%d exception:%s' % (url , j , str (e ))
403
+ exception_logbuf .append (exception_log )
401
404
if j < self ._retry and (isinstance (e , ConnectionError ) or isinstance (e , Timeout )): # 只重试网络错误
402
405
if client_can_retry (file_position , ** kwargs ):
403
406
if not domain_switched and self ._conf ._auto_switch_domain_on_retry and self ._conf ._ip is None :
404
407
url = switch_hostname_for_url (url )
405
408
domain_switched = True
406
409
continue
410
+ logger .exception (exception_logbuf ) # 最终重试失败, 输出前几次重试失败的exception
407
411
raise CosClientError (str (e ))
408
412
409
413
if not cos_request :
@@ -419,12 +423,16 @@ def send_request(self, method, url, bucket, timeout=30, cos_request=True, ci_req
419
423
if 'x-cos-trace-id' in res .headers :
420
424
info ['traceid' ] = res .headers ['x-cos-trace-id' ]
421
425
logger .warn (info )
426
+ if len (exception_logbuf ) > 0 :
427
+ logger .exception (exception_logbuf ) # 最终重试失败, 输出前几次重试失败的exception
422
428
raise CosServiceError (method , info , res .status_code )
423
429
else :
424
430
msg = res .text
425
431
if msg == u'' : # 服务器没有返回Error Body时 给出头部的信息
426
432
msg = res .headers
427
433
logger .error (msg )
434
+ if len (exception_logbuf ) > 0 :
435
+ logger .exception (exception_logbuf ) # 最终重试失败, 输出前几次重试失败的exception
428
436
raise CosServiceError (method , msg , res .status_code )
429
437
430
438
return None
0 commit comments