22export default function contentstckRetry ( axios , defaultOptions , retryLimit = 5 , retryDelay = 300 ) {
33 var networkError = 0
44 axios . interceptors . request . use ( function ( config ) {
5+ config . retryCount = config . retryCount || 0
56 if ( config . headers . authorization && config . headers . authorization !== undefined ) {
67 delete config . headers . authtoken
78 }
@@ -13,15 +14,23 @@ export default function contentstckRetry (axios, defaultOptions, retryLimit = 5,
1314 } , function ( error ) {
1415 var wait = retryDelay
1516 let retryErrorType = null
16- if ( ! defaultOptions . retryOnError ) {
17- return Promise . reject ( error )
18- }
19-
2017 var response = error . response
18+ networkError = error . config . retryCount
2119 if ( ! response ) {
22- retryErrorType = `Server connection`
20+ if ( error . code === 'ECONNABORTED' ) {
21+ error . response = {
22+ ...error . response ,
23+ status : 408 ,
24+ statusText : `timeout of ${ defaultOptions . timeout } ms exceeded`
25+ }
26+ } else {
27+ return Promise . reject ( error )
28+ }
29+ }
30+ if ( ! defaultOptions . retryOnError ) {
2331 return Promise . reject ( error )
2432 }
33+
2534 if ( defaultOptions . retryCondition && defaultOptions . retryCondition ( error ) ) {
2635 retryErrorType = `Error with status: ${ error . response . status } `
2736 networkError ++
@@ -46,6 +55,8 @@ export default function contentstckRetry (axios, defaultOptions, retryLimit = 5,
4655 networkError = 0
4756 }
4857
58+ error . config . retryCount = networkError
59+
4960 if ( retryErrorType && error . config !== undefined ) {
5061 var config = error . config
5162 defaultOptions . logHandler ( 'warning' , `${ retryErrorType } error occurred. Waiting for ${ wait } ms before retrying...` )
0 commit comments