Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(scrapeURL/pdf): better timeout error for PDF scrapes (#1942)

Gergő Móriczf5b73b647684
diff --git a/apps/api/src/scraper/scrapeURL/engines/pdf/index.ts b/apps/api/src/scraper/scrapeURL/engines/pdf/index.ts
index 6649c735d..739f590fa 100644
--- a/apps/api/src/scraper/scrapeURL/engines/pdf/index.ts
+++ b/apps/api/src/scraper/scrapeURL/engines/pdf/index.ts
@@ -280,8 +280,10 @@ export async function scrapePDF(
error.message === "Request failed" &&
error.cause &&
error.cause instanceof Error &&
- error.cause.name === "TimeoutError")
+ error.cause.name === "TimeoutError") ||
+ (error instanceof Error && error.name === "TimeoutSignal")
) {
+ meta.logger.warn("RunPod MU timed out");
throw new TimeoutError(
"PDF parsing timed out, please increase the timeout parameter in your scrape request",
);
diff --git a/apps/api/src/scraper/scrapeURL/index.ts b/apps/api/src/scraper/scrapeURL/index.ts
index be4f0310e..9b3628abc 100644
--- a/apps/api/src/scraper/scrapeURL/index.ts
+++ b/apps/api/src/scraper/scrapeURL/index.ts
@@ -244,6 +244,7 @@ export type EngineResultsTracker = {
}
| {
state: "timeout";
+ error: any;
}
) & {
startedAt: number;
@@ -384,6 +385,7 @@ async function scrapeURLLoop(meta: Meta): Promise<ScrapeUrlResponse> {
state: "timeout",
startedAt,
finishedAt: Date.now(),
+ error: safeguardCircularError(error),
};
} else if (
error instanceof AddFeatureError ||
@@ -443,6 +445,9 @@ async function scrapeURLLoop(meta: Meta): Promise<ScrapeUrlResponse> {
}
if (result === null) {
+ if (meta.results["pdf"]?.state === "timeout") {
+ throw meta.results["pdf"].error ?? new TimeoutSignal();
+ }
if (Object.values(meta.results).every(x => x.state === "timeout")) {
throw new TimeoutSignal();
} else {