From 6b4dae8eebf689d3d34040ef197df871926a54b6 Mon Sep 17 00:00:00 2001 From: Martin Porwoll Date: Mon, 16 Feb 2026 16:32:32 +0000 Subject: [PATCH] fix: handle non-JSON responses in test email and prevent cascading failures - Add content-type check in TestEmailButton before parsing response as JSON - Wrap updateEmailLog in error handler with try-catch to prevent double failures Co-Authored-By: Claude Opus 4.6 --- src/components/admin/TestEmailButton.tsx | 10 ++++++++++ src/lib/email/tenant-email-service.ts | 12 ++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/admin/TestEmailButton.tsx b/src/components/admin/TestEmailButton.tsx index b172520..fd13c07 100644 --- a/src/components/admin/TestEmailButton.tsx +++ b/src/components/admin/TestEmailButton.tsx @@ -126,6 +126,16 @@ export const TestEmailButton: React.FC = () => { }), }) + const contentType = response.headers.get('content-type') || '' + if (!contentType.includes('application/json')) { + setResult({ + success: false, + message: `Server-Fehler (HTTP ${response.status}). Bitte Seite neu laden und erneut versuchen.`, + }) + setStatus('error') + return + } + const data = await response.json() if (response.ok && data.success) { diff --git a/src/lib/email/tenant-email-service.ts b/src/lib/email/tenant-email-service.ts index c15829e..633bf0f 100644 --- a/src/lib/email/tenant-email-service.ts +++ b/src/lib/email/tenant-email-service.ts @@ -264,10 +264,14 @@ export async function sendTenantEmail( // Log aktualisieren (status: failed) if (logId) { - await updateEmailLog(payload, logId, { - status: 'failed', - error: errorMessage, - }) + try { + await updateEmailLog(payload, logId, { + status: 'failed', + error: errorMessage, + }) + } catch (logError) { + console.error(`[Email] Failed to update email log ${logId}:`, logError) + } } console.error(`[Email] Error for tenant ${tenantId}:`, error)