Improve invoice sending by proxying through backend

Replaces direct webhook calls for invoice sending with a backend API endpoint, utilizing multer for file uploads and form-data for robust data transmission. Includes improved error handling and logging.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 1e4433b5-47ab-464c-b663-fea2e53367dd
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: e89da884-7d51-4b3d-8af5-22493ce6f2c1
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/1e4433b5-47ab-464c-b663-fea2e53367dd/qOJ89TE
This commit is contained in:
michaelschal committed 2025-11-04 15:17:17 +00:00
1 parent 4dffada355
commit 89211e4f28
6 files changed
+357 -50

No files matched your search

+8 -9
View File
@@ -515,26 +515,25 @@ export default function BLReconciliation() {
try {
const formData = new FormData();
formData.append('file', selectedFile);
formData.append('webhookUrl', selectedDeliveryForInvoice.group.webhookUrl);
formData.append('supplier', selectedDeliveryForInvoice.supplier?.name || '');
formData.append('blNumber', selectedDeliveryForInvoice.blNumber || '');
formData.append('type', 'Facture');
// Créer un AbortController pour gérer le timeout
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 60000); // 60 secondes
const response = await fetch(selectedDeliveryForInvoice.group.webhookUrl, {
// Envoyer via notre route backend proxy (évite problèmes CORS et erreurs webhook)
const response = await fetch('/api/reconciliation/send-invoice', {
method: 'POST',
body: formData,
signal: controller.signal,
credentials: 'include' // Important pour l'authentification
});
clearTimeout(timeoutId);
if (!response.ok) {
throw new Error(`Erreur ${response.status}: ${response.statusText}`);
const errorData = await response.json().catch(() => ({}));
throw new Error(errorData.error || `Erreur ${response.status}: ${response.statusText}`);
}
const result = await response.json();
handleCloseWaitingModal();
toast({