Skip to content

Commit

Permalink
Merge pull request #116 from mrrfv/mrrfv-patch-1
Browse files Browse the repository at this point in the history
Error handling improvements
  • Loading branch information
mrrfv authored Jun 9, 2024
2 parents a5d3fdb + cd4a5ae commit 6d1b605
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const request = async (url, options) => {
let response;
let data;
let attempts = 0;
let maxAttempts = 50;

while(attempts < 50) {
try {
Expand All @@ -123,10 +124,11 @@ const request = async (url, options) => {
return data;
} catch (error) {
attempts++;
if(attempts >= 50) {
console.warn(`An error occured while making a web request: "${error}", retrying. Attempt ${attempts} of ${maxAttempts}.`)
if(attempts >= maxAttempts) {
// Send a message to the Discord webhook if it exists
await notifyWebhook(`An HTTP error has occurred (${response.status}) while making a web request. Please check the logs for further details.`);
throw new Error(`HTTP error! Status: ${response.status} - ${ 'errors' in data ? data.errors[0].message : JSON.stringify(data) }`);
await notifyWebhook(`An HTTP error has occurred (${response ? response.status : "unknown status"}) while making a web request. Please check the logs for further details.`);
throw new Error(`HTTP error! Status: ${response.status} - ${ (data && 'errors' in data) ? data.errors[0].message : data } - ${error}`);
}
await wait(5000);
}
Expand Down

0 comments on commit 6d1b605

Please sign in to comment.