From e7db4e23f52fa706e673cccd6409ce41497b3d62 Mon Sep 17 00:00:00 2001 From: Vladislav Date: Mon, 22 Jul 2024 10:41:30 +0200 Subject: [PATCH] update error handling (#100) --- lib/services/requestDriver.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/services/requestDriver.js b/lib/services/requestDriver.js index 7d42c5e..4a91eac 100644 --- a/lib/services/requestDriver.js +++ b/lib/services/requestDriver.js @@ -24,13 +24,16 @@ function makeDriver(headers = {}) { }, }); const result = await response.text(); + if (EXPECTED_STATUS_CODES.includes(response.status)) { + throw new Error(`${response.status}`); + } if (cookies.length === 0) { cookies = response.headers.raw()['set-cookie'] || []; } callback(null, result); } catch (exception) { /* eslint-disable no-console */ - if (!EXPECTED_STATUS_CODES.includes(exception.response?.status)) { + if (!EXPECTED_STATUS_CODES.includes(exception.response?.status) && !EXPECTED_STATUS_CODES.includes(Number(exception.message))) { console.error(`Error while trying to scrape data from scraping ant. Received error: ${exception.message}`); callback(null, []); return;