From 3815d246288cca3944ca3b8733b8964f31300f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=B3ricz=20Gerg=C5=91?= Date: Tue, 12 Nov 2024 13:16:40 +0100 Subject: [PATCH] fix(scrape): better timeout handling --- apps/api/src/controllers/v0/scrape.ts | 2 +- apps/api/src/controllers/v0/search.ts | 2 +- apps/api/src/controllers/v1/scrape.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/api/src/controllers/v0/scrape.ts b/apps/api/src/controllers/v0/scrape.ts index 05fb3c41..9bc41fc1 100644 --- a/apps/api/src/controllers/v0/scrape.ts +++ b/apps/api/src/controllers/v0/scrape.ts @@ -86,7 +86,7 @@ export async function scrapeHelper( try { doc = (await waitForJob(jobId, timeout)); } catch (e) { - if (e instanceof Error && e.message.startsWith("Job wait")) { + if (e instanceof Error && (e.message.startsWith("Job wait") || e.message === "timeout")) { span.setAttribute("timedOut", true); return { success: false, diff --git a/apps/api/src/controllers/v0/search.ts b/apps/api/src/controllers/v0/search.ts index e0102406..4dd38afd 100644 --- a/apps/api/src/controllers/v0/search.ts +++ b/apps/api/src/controllers/v0/search.ts @@ -196,7 +196,7 @@ export async function searchController(req: Request, res: Response) { }); return res.status(result.returnCode).json(result); } catch (error) { - if (error instanceof Error && error.message.startsWith("Job wait")) { + if (error instanceof Error && (error.message.startsWith("Job wait") || error.message === "timeout")) { return res.status(408).json({ error: "Request timed out" }); } diff --git a/apps/api/src/controllers/v1/scrape.ts b/apps/api/src/controllers/v1/scrape.ts index 76fab433..9c85c91e 100644 --- a/apps/api/src/controllers/v1/scrape.ts +++ b/apps/api/src/controllers/v1/scrape.ts @@ -56,7 +56,7 @@ export async function scrapeController( doc = await waitForJob(jobId, timeout + totalWait); // TODO: better types for this } catch (e) { logger.error(`Error in scrapeController: ${e}`); - if (e instanceof Error && e.message.startsWith("Job wait")) { + if (e instanceof Error && (e.message.startsWith("Job wait") || e.message === "timeout")) { return res.status(408).json({ success: false, error: "Request timed out",