From fd6b490de10aba70fe588ecda7acaabd8e5eea8b Mon Sep 17 00:00:00 2001 From: Sean O'Connor Date: Mon, 24 Nov 2025 21:47:47 -0500 Subject: [PATCH] Remove debug logging and simplify error handling --- src/lib/pdf-export.tsx | 67 ++++++++++-------------------------------- 1 file changed, 16 insertions(+), 51 deletions(-) diff --git a/src/lib/pdf-export.tsx b/src/lib/pdf-export.tsx index 6a3d0e4..1504254 100644 --- a/src/lib/pdf-export.tsx +++ b/src/lib/pdf-export.tsx @@ -12,14 +12,6 @@ import React from "react"; // Fallback download function for better browser compatibility function downloadBlob(blob: Blob, filename: string): void { - // Enhanced debugging for download process - console.log("Download Debug Info:", { - blobSize: blob.size, - blobType: blob.type, - filename: filename, - userAgent: navigator.userAgent, - }); - try { // Validate blob before download if (!blob || blob.size === 0) { @@ -28,38 +20,25 @@ function downloadBlob(blob: Blob, filename: string): void { // First try using file-saver saveAs(blob, filename); - console.log("PDF download initiated successfully via file-saver"); } catch (error) { - console.warn("file-saver failed, using fallback method:", 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"; - 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"); + // Add MIME type hint to link + if (blob.type) { + link.type = blob.type; } + + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + // Clean up the object URL + setTimeout(() => URL.revokeObjectURL(url), 1000); } } @@ -1106,20 +1085,6 @@ export async function generateInvoicePDF(invoice: InvoiceData): Promise { // Create a new blob with explicit MIME type to ensure proper PDF handling const blob = new Blob([originalBlob], { type: "application/pdf" }); - // Enhanced debugging - console.log("PDF Generation Debug Info:", { - originalBlobSize: originalBlob.size, - originalBlobType: originalBlob.type, - newBlobSize: blob.size, - newBlobType: blob.type, - invoiceNumber: invoice.invoiceNumber, - }); - - // Validate MIME type is set correctly - if (blob.type !== "application/pdf") { - console.warn("MIME type not set correctly, forcing application/pdf"); - } - // Create filename with timestamp for uniqueness const timestamp = new Date().toISOString().slice(0, 10); const filename = `Invoice_${invoice.invoiceNumber}_${timestamp}.pdf`;