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.
This commit is contained in:
2025-11-25 00:37:49 -05:00
parent fd6b490de1
commit a69b8f029b

View File

@@ -21,6 +21,9 @@ function downloadBlob(blob: Blob, filename: string): void {
// First try using file-saver
saveAs(blob, filename);
} catch (error) {
console.warn("file-saver failed, using fallback method:", error);
try {
// Fallback to manual download
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
@@ -37,8 +40,17 @@ function downloadBlob(blob: Blob, filename: string): void {
link.click();
document.body.removeChild(link);
console.log("PDF download initiated successfully via fallback method");
// Clean up the object URL
setTimeout(() => URL.revokeObjectURL(url), 1000);
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");
}
}
}