Skip to content

Commit b0b6ee1

Browse files
authored
Merge pull request #17 from contentstack/bug/timeout-retry
fix: 🐛 Request time out retry bug resolved
2 parents 5eedd8d + f86a144 commit b0b6ee1

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

.talismanrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fileignoreconfig:
2+
- filename: jsdocs/stack_environment_index.js.html
3+
checksum: e70125d5038c16be4c974b75780b252d2ba680f63a791dc788941996d6e2b2bc
4+
- filename: .talisman
5+
checksum: ef29fbb058801114e565011d7b292a00e86dd385ff2e77a06ddf62b253339d99
6+
- filename: dist/node/contentstack-management.js
7+
checksum: d0a2881a9f533cb24cd909792548617f70aea637d6f7ca0ff932ede72e5e57ee
8+
- filename: dist/react-native/contentstack-management.js
9+
checksum: 3f611ee5cc82bf3cf4135de830208ce448184c99364538435f35c6c67aaf2d9e
10+
- filename: dist/web/contentstack-management.js
11+
checksum: 8bf55c1cf4b9f59d2c47ae16e7b6b6476eab8b7aefb817a560a41f9c3c76b337
12+
- filename: dist/nativescript/contentstack-management.js
13+
checksum: b514e4144664db6b107c412655a36028e102e25b901ede0ee782be03e2380d14

lib/core/concurrency-queue.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function ConcurrencyQueue ({ axios, config }) {
6969
}
7070
}
7171

72-
// Request interseptor to queue the request
72+
// Request interceptor to queue the request
7373
const requestHandler = request => {
7474
request.retryCount = request.retryCount || 0
7575
if (request.headers.authorization && request.headers.authorization !== undefined) {
@@ -130,15 +130,16 @@ export function ConcurrencyQueue ({ axios, config }) {
130130
}
131131

132132
// Error handling
133-
let wait = this.config.retryDelay
134-
const response = error.response
133+
const wait = this.config.retryDelay
134+
var response = error.response
135135
if (!response) {
136136
if (error.code === 'ECONNABORTED') {
137137
error.response = {
138138
...error.response,
139139
status: 408,
140140
statusText: `timeout of ${this.config.timeout}ms exceeded`
141141
}
142+
response = error.response
142143
} else {
143144
return Promise.reject(responseHandler(error))
144145
}
@@ -150,38 +151,43 @@ export function ConcurrencyQueue ({ axios, config }) {
150151
return Promise.reject(responseHandler(error))
151152
}
152153
this.running.shift()
153-
wait = 1000
154-
// Cooldown the running requests
154+
// Cool down the running requests
155155
delay(wait)
156156
error.config.retryCount = networkError
157157

158158
return axios(updateRequestConfig(error, retryErrorType, wait))
159-
} else if (this.config.retryCondition && this.config.retryCondition(error)) {
160-
retryErrorType = `Error with status: ${response.status}`
159+
}
160+
if (this.config.retryCondition && this.config.retryCondition(error)) {
161+
retryErrorType = error.response ? `Error with status: ${response.status}` : `Error Code:${error.code}`
161162
networkError++
162-
if (networkError > this.config.retryLimit) {
163-
return Promise.reject(responseHandler(error))
164-
}
165-
if (this.config.retryDelayOptions) {
166-
if (this.config.retryDelayOptions.customBackoff) {
167-
wait = this.config.retryDelayOptions.customBackoff(networkError, error)
168-
if (wait && wait <= 0) {
169-
return Promise.reject(responseHandler(error))
170-
}
171-
} else if (this.config.retryDelayOptions.base) {
172-
wait = this.config.retryDelayOptions.base * networkError
163+
return this.retry(error, retryErrorType, networkError, wait)
164+
}
165+
return Promise.reject(responseHandler(error))
166+
}
167+
168+
this.retry = (error, retryErrorType, retryCount, waittime) => {
169+
let delaytime = waittime
170+
if (retryCount > this.config.retryLimit) {
171+
return Promise.reject(responseHandler(error))
172+
}
173+
if (this.config.retryDelayOptions) {
174+
if (this.config.retryDelayOptions.customBackoff) {
175+
delaytime = this.config.retryDelayOptions.customBackoff(retryCount, error)
176+
if (delaytime && delaytime <= 0) {
177+
return Promise.reject(responseHandler(error))
173178
}
174-
} else {
175-
wait = this.config.retryDelay
179+
} else if (this.config.retryDelayOptions.base) {
180+
delaytime = this.config.retryDelayOptions.base * retryCount
176181
}
177-
error.config.retryCount = networkError
178-
return new Promise(function (resolve) {
179-
return setTimeout(function () {
180-
return resolve(axios(updateRequestConfig(error, retryErrorType, wait)))
181-
}, wait)
182-
})
182+
} else {
183+
delaytime = this.config.retryDelay
183184
}
184-
return Promise.reject(responseHandler(error))
185+
error.config.retryCount = retryCount
186+
return new Promise(function (resolve) {
187+
return setTimeout(function () {
188+
return resolve(axios(updateRequestConfig(error, retryErrorType, delaytime)))
189+
}, delaytime)
190+
})
185191
}
186192

187193
this.interceptors = {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/management",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"description": "The Content Management API is used to manage the content of your Contentstack account",
55
"main": "dist/node/contentstack-management.js",
66
"browser": "dist/web/contentstack-management.js",

0 commit comments

Comments
 (0)