fix(scrape): better timeout handling
This commit is contained in:
@@ -86,7 +86,7 @@ export async function scrapeHelper(
|
|||||||
try {
|
try {
|
||||||
doc = (await waitForJob<Document>(jobId, timeout));
|
doc = (await waitForJob<Document>(jobId, timeout));
|
||||||
} catch (e) {
|
} 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);
|
span.setAttribute("timedOut", true);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ export async function searchController(req: Request, res: Response) {
|
|||||||
});
|
});
|
||||||
return res.status(result.returnCode).json(result);
|
return res.status(result.returnCode).json(result);
|
||||||
} catch (error) {
|
} 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" });
|
return res.status(408).json({ error: "Request timed out" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export async function scrapeController(
|
|||||||
doc = await waitForJob<Document>(jobId, timeout + totalWait); // TODO: better types for this
|
doc = await waitForJob<Document>(jobId, timeout + totalWait); // TODO: better types for this
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(`Error in scrapeController: ${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({
|
return res.status(408).json({
|
||||||
success: false,
|
success: false,
|
||||||
error: "Request timed out",
|
error: "Request timed out",
|
||||||
|
|||||||
Reference in New Issue
Block a user