mirror of
https://github.com/soconnor0919/beenvoice.git
synced 2025-12-13 01:24:44 -05:00
Remove debug logging and simplify error handling
This commit is contained in:
@@ -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<void> {
|
||||
// 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`;
|
||||
|
||||
Reference in New Issue
Block a user