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 <noreply@anthropic.com>
This commit is contained in:
Martin Porwoll 2026-02-16 16:32:32 +00:00
parent 0c222b9aa9
commit 6b4dae8eeb
2 changed files with 18 additions and 4 deletions

View file

@ -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) {

View file

@ -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)