Handle worker email send failures

This commit is contained in:
Dorian
2026-06-07 07:51:20 +01:00
parent 2e4db34d2e
commit 9857ec3f57
2 changed files with 36 additions and 7 deletions

View File

@@ -219,9 +219,10 @@ async function handleSubmit(data, env, ctx) {
try {
const ip = data._ip || "unknown";
if (ip !== "unknown" && env.RATE_LIMIT) {
const key = `submit:${ip}`;
const emailKey = String(data.email || "unknown").trim().toLowerCase();
const key = `submit:${ip}:${emailKey}`;
const hits = parseInt(await env.RATE_LIMIT.get(key) || "0", 10);
if (hits >= 5) return json({ ok: false, error: "Too many submissions. Please try again later." }, 429);
if (hits >= 20) return json({ ok: false, error: "Too many submissions. Please try again later." }, 429);
await env.RATE_LIMIT.put(key, String(hits + 1), { expirationTtl: 3600 });
}
} catch (err) {

View File

@@ -1776,16 +1776,44 @@ function submitCapture(e) {
}),
workerTimeout
])
.then(res => res && res.ok ? res.json() : null)
.then(async res => {
if (!res || !res.ok) {
let message = currentLang === 'de'
? 'Dein Plan konnte gerade nicht per E-Mail gesendet werden. Bitte versuche es in ein paar Minuten erneut.'
: 'Your plan could not be emailed just now. Please try again in a few minutes.'
try {
const errData = await res.json()
if (errData && errData.error) message = errData.error
} catch {}
throw new Error(message)
}
return res.json()
})
.then(data => {
if (!data || !data.report_id || !data.report_token) return
if (!data || !data.report_id || !data.report_token) {
throw new Error(currentLang === 'de'
? 'Dein Plan konnte gerade nicht gespeichert werden. Bitte versuche es erneut.'
: 'Your plan could not be saved just now. Please try again.')
}
answers._report_id = String(data.report_id)
answers._report_token = String(data.report_token)
saveState()
showSuccess()
})
.catch(err => {
const btn = document.querySelector('#capture-form button[type="submit"]')
const sub = document.querySelector('#capture-modal .capture-sub')
if (btn) {
btn.disabled = false
btn.innerHTML = `<span>${T[currentLang].capture_btn}</span>`
}
if (sub) {
sub.style.display = 'block'
sub.textContent = err.message || (currentLang === 'de'
? 'Dein Plan konnte gerade nicht gesendet werden. Bitte versuche es erneut.'
: 'Your plan could not be sent just now. Please try again.')
}
})
.catch(() => {})
setTimeout(showSuccess, 1500)
}
// ══════════════════════════════════════