@@ -1081,6 +1081,7 @@ https://github.com/Tencent/APIJSON/issues
10811081 scriptType : 'case' ,
10821082 scriptBelongId : 0 ,
10831083 scripts : newDefaultScript ( ) ,
1084+ retry : 0 , // 每个请求前的等待延迟
10841085 wait : 0 , // 每个请求前的等待延迟
10851086 timeout : null , // 每个请求的超时时间
10861087 loadingCount : 0 ,
@@ -6427,7 +6428,7 @@ https://github.com/Tencent/APIJSON/issues
64276428 } ,
64286429
64296430 //请求
6430- request : function ( isAdminOperation , method , type , url , req , header , callback , caseScript_ , accountScript_ , globalScript_ , ignorePreScript , timeout_ , wait_ ) {
6431+ request : function ( isAdminOperation , method , type , url , req , header , callback , caseScript_ , accountScript_ , globalScript_ , ignorePreScript , timeout_ , wait_ , retry_ ) {
64316432 this . loadingCount ++
64326433
64336434 const isEnvCompare = this . isEnvCompareEnabled
@@ -6438,6 +6439,24 @@ https://github.com/Tencent/APIJSON/issues
64386439 const caseScript = ( isAdminOperation ? null : caseScript_ ) || { }
64396440 const timeout = timeout_ != null ? timeout_ : this . timeout
64406441 const wait = wait_ != null ? wait_ : ( this . wait || 0 )
6442+ var retry = retry_ != null ? retry_ : ( this . retry || 0 )
6443+ var retryReq = function ( ) {
6444+ if ( retry == null || retry <= 0 ) {
6445+ return false
6446+ }
6447+
6448+ retry --
6449+ try {
6450+ sendRequest ( isAdminOperation , method , type , url , req , header , callback )
6451+ } catch ( e ) {
6452+ App . log ( 'request retryReq retry = ' + retry + ' >> try {\n' +
6453+ ' sendRequest(isAdminOperation, method, type, url, req, header, callback)\n' +
6454+ ' } catch (e) = ' + e . message )
6455+ return retryReq ( )
6456+ }
6457+
6458+ return true
6459+ }
64416460
64426461 var evalPostScript = function ( ) { }
64436462
@@ -6558,6 +6577,10 @@ https://github.com/Tencent/APIJSON/issues
65586577 App . onResponse ( url , res , null )
65596578 } )
65606579 . catch ( function ( err ) {
6580+ if ( retryReq ( ) ) {
6581+ return ;
6582+ }
6583+
65616584 var errObj = err instanceof Array == false && err instanceof Object ? err : { }
65626585 var res = { status : errObj . status || ( errObj . response || { } ) . status , request : { url : url , headers : header , data : req } , data : ( errObj . response || { } ) . data }
65636586 App . currentHttpResponse = res
0 commit comments