From 23104c85a5ab4b83d2ff5f28a5e9ab5cff809b5c Mon Sep 17 00:00:00 2001 From: G <41178744+catomean@users.noreply.github.com> Date: Sat, 29 Aug 2026 09:37:03 +0200 Subject: [PATCH] fix(cron): say which thing is actually broken MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /api/cron/emails returned {"error":"Database unavailable"} while the database was fine — psql connects with the app's own DATABASE_URL and the schema has 25 tables. The route hardcoded one of the workflow's two possible errors, so an email-configuration failure was reported as a database failure. The log line beside it made the same mistake in the other direction: it said "RESEND_API_KEY not configured" while the key was present, 36 characters and correctly prefixed re_. isEmailConfigured() is false for TWO reasons, and the second one — a sandbox sender, which is exactly the case the guard was written for — announced the first. Both now name the reason that applies. The guard itself is correct and stays: refusing to mark a queue sent when the sender reaches nobody is the whole point of it. The underlying condition is unchanged and is an operator decision: RESEND_FROM is a sandbox address, so no patient email can be delivered until a verified domain is set. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01UvjGNAS9CMfEGNW26tUR4P --- app/api/cron/emails/route.ts | 5 ++++- lib/workflows/cron-emails.ts | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/api/cron/emails/route.ts b/app/api/cron/emails/route.ts index 8a832bc..066f94c 100644 --- a/app/api/cron/emails/route.ts +++ b/app/api/cron/emails/route.ts @@ -10,7 +10,10 @@ export async function GET(req: Request) { const result = await runCronEmails(); if (!result.success) { - return NextResponse.json({ success: false, error: "Database unavailable" }, { status: 500 }); + // Report the cause the workflow actually returned. Hardcoding one of the + // two made an email-configuration failure read as a database failure, and + // the operator chased Postgres while the sender address was the problem. + return NextResponse.json({ success: false, error: result.error }, { status: 500 }); } return NextResponse.json(result); } diff --git a/lib/workflows/cron-emails.ts b/lib/workflows/cron-emails.ts index fe5840e..faf16b4 100644 --- a/lib/workflows/cron-emails.ts +++ b/lib/workflows/cron-emails.ts @@ -28,7 +28,15 @@ export async function runCronEmails(now: Date = new Date()): Promise