refs #4823 Removed criticalError in vnRequest
This commit is contained in:
parent
b1de54db1e
commit
b9cc8f1a7c
|
@ -25,7 +25,9 @@ SYNC_ORGANIZATION = true
|
|||
SYNC_WAREHOUSE = true
|
||||
SYNC_CONN = true
|
||||
SYNC_TRADEITEM = true
|
||||
MAX_REQUEST_ATTEMPTS = 3
|
||||
|
||||
#REQUEST CONFIG
|
||||
MS_RETRY_UNHANDLED_ERROR = 900000
|
||||
|
||||
#DEV OPTIONS
|
||||
SUPPLIERS_ALWAYS_CONN = false
|
||||
|
|
18
utils.js
18
utils.js
|
@ -540,11 +540,11 @@ export async function vnRequest(method, url, data, headers) {
|
|||
'X-Api-Key': process.env.API_KEY,
|
||||
};
|
||||
|
||||
for(let i = 0; i < env.MAX_REQUEST_ATTEMPTS; i++) {
|
||||
while(true) {
|
||||
try {
|
||||
return (['GET', 'DELETE'].includes(method))
|
||||
? await axios({method, url, headers})
|
||||
: axios({method, url, data, headers});
|
||||
: await axios({method, url, data, headers});
|
||||
} catch (err) {
|
||||
switch (err.code) {
|
||||
case 'ECONNRESET': // Client network socket TLS
|
||||
|
@ -572,10 +572,16 @@ export async function vnRequest(method, url, data, headers) {
|
|||
? headers.Authorization = `Bearer ${await getCurrentToken()}`
|
||||
: criticalError(err);
|
||||
break;
|
||||
default: criticalError(err);
|
||||
default:
|
||||
warning(err);
|
||||
await sleep(env.MS_RETRY_UNHANDLED_ERROR);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default: criticalError(err);
|
||||
default:
|
||||
warning(err);
|
||||
await sleep(env.MS_RETRY_UNHANDLED_ERROR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -597,5 +603,7 @@ export async function criticalError(err) {
|
|||
* @param {err}
|
||||
**/
|
||||
export async function warning(err) {
|
||||
console.log(chalk.yellow.bold(`[WARNING]`), chalk.yellow(err.message));
|
||||
(err.response?.status && err.response?.data?.message)
|
||||
? (console.log(chalk.yellow.bold(`[WARNING]`), chalk.yellow(`${err.response.status} - ${err.response.data.message}`)))
|
||||
: (console.log(chalk.yellow.bold(`[WARNING]`), chalk.yellow(err.message)));
|
||||
}
|
Loading…
Reference in New Issue