fix: enhance PDF generation error handling and timeout settings in puppeteer service

This commit is contained in:
Marco Pedone 2026-03-10 09:56:33 +01:00
parent f364e79aaf
commit 464e5285a1

View file

@ -196,7 +196,13 @@ const puppeteerGenPdf = async ({
: `http://host.docker.internal:3000`;
const targetUrl = `${baseUrl}${url}`;
await page.goto(targetUrl, { waitUntil: "networkidle0" });
try {
await page.goto(targetUrl, { waitUntil: "networkidle2", timeout: 60000 });
} catch (e) {
if ((e as Error).message.includes("detached")) {
await page.goto(targetUrl, { waitUntil: "load", timeout: 60000 });
} else throw e;
}
const pdf = await page.pdf({
format: "A4",
@ -206,7 +212,7 @@ const puppeteerGenPdf = async ({
} catch (error) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Errore nella generazione del PDF: ${(error as Error).message}`,
message: `Errore nella generazione del PDF, URL: ${url}, ${(error as Error).message}`,
});
} finally {
// 'disconnect' tells browserless you're done with this tab