From a01dd2a7b77dd73d4310e1828a46157e6f7464ab Mon Sep 17 00:00:00 2001 From: Aaro Varis Date: Sat, 21 Sep 2024 22:23:14 +0300 Subject: [PATCH] Refactor error handling in main function --- index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 09ba5f8..3fddc94 100644 --- a/index.js +++ b/index.js @@ -59,7 +59,18 @@ async function main() { data: response.data }); } catch (error) { - console.error(error); + if (RETRY_ERROR_CODES.includes(error.response.status)) { + console.log(`Retrying request ${requestObj.id} for instance ${instanceId}`); + SetTimeout(() => { + DoRequest(instanceId, requestObj); + }, 5000); + } else { + RegisterResponse(instanceId, { + id: requestObj.id, + data: error.response.data, + error: "yep there was an error" + }); + } } }