From a69b8f029b5352ce11ea2202043ae42ef8add85b Mon Sep 17 00:00:00 2001 From: Sean O'Connor Date: Tue, 25 Nov 2025 00:37:49 -0500 Subject: [PATCH] Improve PDF export error handling and logging Add detailed logging for file-saver failures and fallback download attempts. Wrap fallback logic in try-catch to handle edge cases where manual download also fails, providing better debugging and user-facing error messages. --- src/lib/pdf-export.tsx | 44 +++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/lib/pdf-export.tsx b/src/lib/pdf-export.tsx index 1504254..d2210fa 100644 --- a/src/lib/pdf-export.tsx +++ b/src/lib/pdf-export.tsx @@ -21,24 +21,36 @@ function downloadBlob(blob: Blob, filename: string): void { // First try using file-saver saveAs(blob, filename); } catch (error) { - // Fallback to manual download - const url = URL.createObjectURL(blob); - const link = document.createElement("a"); - link.href = url; - link.download = filename; - link.style.display = "none"; + console.warn("file-saver failed, using fallback method:", error); - // Add MIME type hint to link - if (blob.type) { - link.type = blob.type; + try { + // Fallback to manual download + const url = URL.createObjectURL(blob); + const link = document.createElement("a"); + link.href = url; + link.download = filename; + link.style.display = "none"; + + // Add MIME type hint to link + if (blob.type) { + link.type = blob.type; + } + + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + console.log("PDF download initiated successfully via fallback method"); + + // Clean up the object URL + setTimeout(() => { + URL.revokeObjectURL(url); + console.log("Object URL cleaned up"); + }, 1000); + } catch (fallbackError) { + console.error("Both download methods failed:", fallbackError); + throw new Error("Unable to download PDF file"); } - - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - - // Clean up the object URL - setTimeout(() => URL.revokeObjectURL(url), 1000); } }