Skip to content

fix(worker): log auto top-up card declines at warn#2969

Merged
steebchen merged 1 commit into
mainfrom
stripe-card-declined-not-error
Jul 9, 2026
Merged

fix(worker): log auto top-up card declines at warn#2969
steebchen merged 1 commit into
mainfrom
stripe-card-declined-not-error

Conversation

@steebchen

@steebchen steebchen commented Jul 9, 2026

Copy link
Copy Markdown
Member

Problem

An off-session auto top-up charge that Stripe declines (code: card_declined, decline_code: generic_decline, etc.) was surfacing in the worker as a logger.error — ERROR severity — which fired production error alerts:

llmgateway-worker … ERROR Error in default
{"err":{"charge":"ch_…","code":"card_declined","decline_code":"generic_decline", …}}

A card decline is an expected outcome of charging a saved card off-session, not a server error.

Fix

In processAutoTopUp()'s catch block, detect Stripe.errors.StripeCardError (insufficient funds, generic_decline, expired card, etc.) and log it at logger.warn instead of logger.error. Genuine, unexpected Stripe failures still log at error level and continue to alert.

This mirrors the existing pattern already used in apps/api/src/routes/payments.ts and the webhook failure handler, which log payment declines at warn level.

Notes

  • No behavior change beyond log level: the pending transaction is still marked failed exactly as before.
  • pnpm build (worker) and pnpm format pass.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved Stripe payment error handling during auto top-ups.
    • Card-decline issues are now logged as warnings, while unexpected payment errors still appear as errors.
    • Error details are now normalized for more consistent diagnostics and troubleshooting.

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>
Copilot AI review requested due to automatic review settings July 9, 2026 17:00
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0c6745dc-675a-459a-b994-99c357cf308a

📥 Commits

Reviewing files that changed from the base of the PR and between bae7652 and 97941e5.

📒 Files selected for processing (1)
  • apps/worker/src/worker.ts

Walkthrough

The processAutoTopUp Stripe error handling path was updated to normalize caught errors into an Error instance and log card-decline errors (StripeCardError) at warn level, while other Stripe errors continue to log at error level.

Changes

Stripe Error Logging Update

Layer / File(s) Summary
Normalize and differentiate Stripe error logging
apps/worker/src/worker.ts
Caught Stripe errors are normalized into an Error object; StripeCardError cases log at warn level, other Stripe errors log at error level using the normalized error object.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: auto top-up card declines are now logged at warn level in the worker.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch stripe-card-declined-not-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@steebchen steebchen merged commit 0d3179f into main Jul 9, 2026
12 checks passed
@steebchen steebchen deleted the stripe-card-declined-not-error branch July 9, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants