2
2
export default function contentstckRetry ( axios , defaultOptions , retryLimit = 5 , retryDelay = 300 ) {
3
3
var networkError = 0
4
4
axios . interceptors . request . use ( function ( config ) {
5
+ config . retryCount = config . retryCount || 0
5
6
if ( config . headers . authorization && config . headers . authorization !== undefined ) {
6
7
delete config . headers . authtoken
7
8
}
@@ -13,15 +14,23 @@ export default function contentstckRetry (axios, defaultOptions, retryLimit = 5,
13
14
} , function ( error ) {
14
15
var wait = retryDelay
15
16
let retryErrorType = null
16
- if ( ! defaultOptions . retryOnError ) {
17
- return Promise . reject ( error )
18
- }
19
-
20
17
var response = error . response
18
+ networkError = error . config . retryCount
21
19
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 ) {
23
31
return Promise . reject ( error )
24
32
}
33
+
25
34
if ( defaultOptions . retryCondition && defaultOptions . retryCondition ( error ) ) {
26
35
retryErrorType = `Error with status: ${ error . response . status } `
27
36
networkError ++
@@ -46,6 +55,8 @@ export default function contentstckRetry (axios, defaultOptions, retryLimit = 5,
46
55
networkError = 0
47
56
}
48
57
58
+ error . config . retryCount = networkError
59
+
49
60
if ( retryErrorType && error . config !== undefined ) {
50
61
var config = error . config
51
62
defaultOptions . logHandler ( 'warning' , `${ retryErrorType } error occurred. Waiting for ${ wait } ms before retrying...` )
0 commit comments