Skip to content

Commit

Permalink
improving resilience
Browse files Browse the repository at this point in the history
  • Loading branch information
icebaker committed Jun 2, 2023
1 parent 445cd96 commit 3a0aa2b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions nanobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class NanoBot {
});
}

static async send_request(config, params, method, path, timeout=undefined) {
static async send_request(config, params, method, path, timeout=undefined, retries=0) {
return new Promise((resolve, reject) => {
const api_url = new url.URL(config.NANO_BOTS_API_ADDRESS);
const options = {
Expand Down Expand Up @@ -121,9 +121,14 @@ class NanoBot {
});
});

request.on('error', (error) => {
vscode.window.showErrorMessage('Nano Bots: ' + error.message);
reject(error);
request.on('error', async (error) => {
if(retries < 2) {
console.warn(`[${retries + 1}] RETRY`);
return await this.send_request(config, params, method, path, timeout, retries);
} else {
vscode.window.showErrorMessage('Nano Bots: ' + error.message);
reject(error);
}
});

if (params) {
Expand Down

0 comments on commit 3a0aa2b

Please sign in to comment.