fix: node would crash if axios throw an error

This commit is contained in:
Christian Kellner
2021-11-11 15:31:53 +01:00
parent ec986e4b18
commit c97b323b35
4 changed files with 38 additions and 8 deletions

View File

@@ -1,4 +1,7 @@
const axios = require('axios');
const axiosRetry = require('axios-retry');
axiosRetry(axios, { retryDelay: axiosRetry.exponentialDelay, retries: 3 });
function makeDriver(headers = {}) {
let cookies = '';
@@ -15,7 +18,8 @@ function makeDriver(headers = {}) {
},
});
} catch (exception) {
callback(exception, null);
console.error(`Error while trying to scrape data. Received error: ${exception.message}`);
callback(null, []);
}
if (typeof result.data === 'object' && url.toLowerCase().indexOf('scrapingant') !== -1) {