Adding recoverable errors

This commit is contained in:
Matias committed 2019-07-20 07:28:05 -03:00
1 parent 86ab8a7642
commit b5e3918f66
1 file changed
+27 -2
+27 -2
View File
@@ -7,6 +7,22 @@ function newFileStorage() {
const MAX_RETRY = 2
let currentRetry = 0
const recoverableErrors = [
'SOCKETTIMEDOUT',
'TIMEDOUT',
'CONNRESET',
'CONNREFUSED',
'NOTFOUND',
'ENOTFOUND',
'ECONNREFUSED',
'CONNREFUSED',
'NOTFOUND',
'ESOCKETTIMEDOUT',
'ECONNRESET',
'ETIMEDOUT',
'EAI_AGAIN'
]
let thisObject = {
getBlobToText: getBlobToText
}
@@ -46,7 +62,6 @@ function newFileStorage() {
headers: headers
})
currentRetry = 0
if (response.data.errors) {
let error = { code: response.data.errors[0] }
callBackFunction(error)
@@ -60,7 +75,7 @@ function newFileStorage() {
}
} catch (err) {
if ((err.code === 'ETIMEDOUT' || err.code === 'ECONNRESET') && currentRetry < MAX_RETRY) {
if (verifyRetry(err.code) && currentRetry < MAX_RETRY) {
currentRetry++
if (INFO_LOG === true) { console.log('[INFO] getTextFile -> Retrying connection to the server because received error: ' + err.code + '. Retry #: ' + currentRetry) }
getBlobToText(container, filePath, host, callBackFunction)
@@ -73,4 +88,14 @@ function newFileStorage() {
}
}
}
function verifyRetry(errorCode) {
for (let i = 0; i < recoverableErrors.length; i++) {
const error = recoverableErrors[i];
if (error === errorCode) {
return true
}
}
return false
}
}