diff --git a/lib/helpers.js b/lib/helpers.js index ec7e30d2..39310993 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -104,6 +104,7 @@ const request = async (url, options) => { let response; let data; let attempts = 0; + let maxAttempts = 50; while(attempts < 50) { try { @@ -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); }