Skip to content

Commit 97941e5

Browse files
steebchenclaude
andcommitted
fix(worker): log auto top-up card declines at warn
Card declines (insufficient funds, generic_decline, expired cards, etc.) are an expected outcome of an off-session auto top-up, not a server error. Detect StripeCardError and log it at warn level so it no longer triggers ERROR-severity alerts; genuine Stripe failures still log at error level. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent bae7652 commit 97941e5

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

apps/worker/src/worker.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,22 @@ export async function processAutoTopUp(): Promise<void> {
571571
.where(eq(tables.transaction.id, pendingTransaction.id));
572572
}
573573
} catch (stripeError) {
574-
logger.error(
575-
`Stripe error for organization ${org.id}`,
574+
const errObj =
576575
stripeError instanceof Error
577576
? stripeError
578-
: new Error(String(stripeError)),
579-
);
577+
: new Error(String(stripeError));
578+
// Card declines (insufficient funds, generic_decline, expired
579+
// cards, etc.) are an expected outcome of an off-session auto
580+
// top-up, not a server error, so log them at warn level to avoid
581+
// noisy error alerts.
582+
if (stripeError instanceof Stripe.errors.StripeCardError) {
583+
logger.warn(
584+
`Auto top-up card declined for organization ${org.id}`,
585+
errObj,
586+
);
587+
} else {
588+
logger.error(`Stripe error for organization ${org.id}`, errObj);
589+
}
580590
// Mark transaction as failed
581591
await db
582592
.update(tables.transaction)

0 commit comments

Comments
 (0)