Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
Add more typechecks
Ondra Urbanc93237d57c71
diff --git a/src/request.js b/src/request.jsindex e078ed6de..18036bc8c 100644--- a/src/request.js+++ b/src/request.js@@ -170,8 +170,12 @@ class Request {case 'object':if (!errorOrMessage) {message = 'Received: "null" instead of a proper message.';+ } else if (Array.isArray(errorOrMessage)) {+ message = `Received: "array" instead of a proper message.\nContents: ${errorOrMessage}`;} else if (errorOrMessage.message) {message = errorOrMessage.message; // eslint-disable-line prefer-destructuring+ } else if (errorOrMessage.toString() !== '[object Object]') {+ message = errorOrMessage.toString();} else {try {message = JSON.stringify(errorOrMessage, null, 2);diff --git a/test/request.js b/test/request.jsindex 99973d7e6..4ecf43800 100644--- a/test/request.js+++ b/test/request.js@@ -27,11 +27,16 @@ describe('Apify.Request', () => {circularObj.obj = circularObj;const arr = [1, 2, 3];- const arrJson = JSON.stringify(arr, null, 2);const obj = { one: 1, two: 'two' };const objJson = JSON.stringify(obj, null, 2);+ const toStr = {+ toString() {+ return 'toString';+ },+ };+request.pushErrorMessage(undefined);request.pushErrorMessage(false);request.pushErrorMessage(5);@@ -43,6 +48,7 @@ describe('Apify.Request', () => {request.pushErrorMessage({ message: 'A message.' });request.pushErrorMessage([1, 2, 3]);request.pushErrorMessage(obj);+ request.pushErrorMessage(toStr);request.pushErrorMessage(circularObj);expect(request.errorMessages).to.be.eql([@@ -55,8 +61,9 @@ describe('Apify.Request', () => {'Received: "null" instead of a proper message.','foo','A message.',- arrJson,+ `Received: "array" instead of a proper message.\nContents: ${arr}`,objJson,+ 'toString','Received an Object that is not stringifiable to JSON and has the following keys: prop; obj',]);});