Merge branch 'main' into v1-webscraper

This commit is contained in:
Gergő Móricz 2024-08-23 19:14:49 +02:00
commit 1054a1397b
2 changed files with 16 additions and 4 deletions

View File

@ -61,6 +61,12 @@ export async function scrapeHelper(
error: "Request timed out",
returnCode: 408,
}
} else if (typeof e === "string" && (e.includes("Error generating completions: ") || e.includes("Invalid schema for function"))) {
return {
success: false,
error: e,
returnCode: 500,
};
} else {
throw e;
}
@ -211,6 +217,6 @@ export async function scrapeController(req: Request, res: Response) {
} catch (error) {
Sentry.captureException(error);
Logger.error(error);
return res.status(500).json({ error: error.message });
return res.status(500).json({ error: typeof error === "string" ? error : (error?.message ?? "Internal Server Error") });
}
}

View File

@ -53,9 +53,15 @@ export function waitForJob(jobId: string, timeout: number) {
if (Date.now() >= start + timeout) {
clearInterval(int);
reject(new Error("Job wait "));
} else if (await getScrapeQueue().getJobState(jobId) === "completed") {
clearInterval(int);
resolve((await getScrapeQueue().getJob(jobId)).returnvalue);
} else {
const state = await getScrapeQueue().getJobState(jobId);
if (state === "completed") {
clearInterval(int);
resolve((await getScrapeQueue().getJob(jobId)).returnvalue);
} else if (state === "failed") {
clearInterval(int);
reject((await getScrapeQueue().getJob(jobId)).failedReason);
}
}
}, 1000);
})