add failover to n8n if not have credits to send emails from cloudflare #79

Merged
esteban merged 1 commits from main into staging 2026-08-03 05:06:06 +00:00
1 changed files with 21 additions and 16 deletions
Showing only changes of commit 8224dd5517 - Show all commits

View File

@ -80,6 +80,7 @@ export async function sendEmailCf(data: Record<string, string>, to: string, type
const apiToken = import.meta.env.CLOUDFLARE_API_TOKEN; const apiToken = import.meta.env.CLOUDFLARE_API_TOKEN;
const accountId = import.meta.env.CLOUDFLARE_ACCOUNT_ID; const accountId = import.meta.env.CLOUDFLARE_ACCOUNT_ID;
try {
const client = new Cloudflare({ apiToken }); const client = new Cloudflare({ apiToken });
const { subject } = TEMPLATE_URLS[type]; const { subject } = TEMPLATE_URLS[type];
const rawHtml = await fetchTemplate(type); const rawHtml = await fetchTemplate(type);
@ -99,6 +100,10 @@ export async function sendEmailCf(data: Record<string, string>, to: string, type
console.error("Cloudflare email not delivered", response); console.error("Cloudflare email not delivered", response);
throw new Error("El correo no fue entregado"); throw new Error("El correo no fue entregado");
} }
} catch (error) {
console.error("Cloudflare email failed, fallback a n8n:", error);
await sendEmail(data, to, type);
}
} }
// ═══════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════