From 42980c899d8b9cb13c63e841665b42b7c7c3bb61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20M=C3=B3ricz?= Date: Thu, 28 Nov 2024 18:41:48 +0100 Subject: [PATCH] fix(scrapeURL/fire-engine): fast fail on chrome error --- .../scrapeURL/engines/fire-engine/checkStatus.ts | 16 ++++++++++------ .../scrapeURL/engines/fire-engine/index.ts | 4 ++-- apps/api/src/scraper/scrapeURL/error.ts | 10 +++++++++- apps/api/src/scraper/scrapeURL/index.ts | 6 +++++- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/apps/api/src/scraper/scrapeURL/engines/fire-engine/checkStatus.ts b/apps/api/src/scraper/scrapeURL/engines/fire-engine/checkStatus.ts index 2c67e196..53c19f3c 100644 --- a/apps/api/src/scraper/scrapeURL/engines/fire-engine/checkStatus.ts +++ b/apps/api/src/scraper/scrapeURL/engines/fire-engine/checkStatus.ts @@ -3,7 +3,7 @@ import * as Sentry from "@sentry/node"; import { z } from "zod"; import { robustFetch } from "../../lib/fetch"; -import { EngineError } from "../../error"; +import { EngineError, SiteError } from "../../error"; const successSchema = z.object({ jobId: z.string(), @@ -90,11 +90,15 @@ export async function fireEngineCheckStatus(logger: Logger, jobId: string): Prom throw new StillProcessingError(jobId); } else if (failedParse.success) { logger.debug("Scrape job failed", { status, jobId }); - throw new EngineError("Scrape job failed", { - cause: { - status, jobId - } - }); + if (typeof status.error === "string" && status.error.includes("Chrome error: ")) { + throw new SiteError(status.error.split("Chrome error: ")[1]); + } else { + throw new EngineError("Scrape job failed", { + cause: { + status, jobId + } + }); + } } else { logger.debug("Check status returned response not matched by any schema", { status, jobId }); throw new Error("Check status returned response not matched by any schema", { diff --git a/apps/api/src/scraper/scrapeURL/engines/fire-engine/index.ts b/apps/api/src/scraper/scrapeURL/engines/fire-engine/index.ts index 17bb40f2..106803ac 100644 --- a/apps/api/src/scraper/scrapeURL/engines/fire-engine/index.ts +++ b/apps/api/src/scraper/scrapeURL/engines/fire-engine/index.ts @@ -3,7 +3,7 @@ import { Meta } from "../.."; import { fireEngineScrape, FireEngineScrapeRequestChromeCDP, FireEngineScrapeRequestCommon, FireEngineScrapeRequestPlaywright, FireEngineScrapeRequestTLSClient } from "./scrape"; import { EngineScrapeResult } from ".."; import { fireEngineCheckStatus, FireEngineCheckStatusSuccess, StillProcessingError } from "./checkStatus"; -import { EngineError, TimeoutError } from "../../error"; +import { EngineError, SiteError, TimeoutError } from "../../error"; import * as Sentry from "@sentry/node"; import { Action } from "../../../../lib/entities"; import { specialtyScrapeCheck } from "../utils/specialtyHandler"; @@ -41,7 +41,7 @@ async function performFireEngineScrape