Skip to content

Skip instead of failing discount cron on Stripe permission errors - #3990

Merged
devkiran merged 2 commits into
mainfrom
fix-discount-code
Jun 5, 2026
Merged

Skip instead of failing discount cron on Stripe permission errors#3990
devkiran merged 2 commits into
mainfrom
fix-discount-code

Conversation

@devkiran

@devkiran devkiran commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for discount code creation: specific permission errors are now logged as warnings and handled gracefully to reduce unnecessary failures and improve observability.

@devkiran
devkiran requested a review from steven-tey June 5, 2026 06:14
@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview Jun 5, 2026 6:30am

Request Review

@coderabbitai

coderabbitai Bot commented Jun 5, 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7d7fb252-9925-4bc0-b10c-18cc657a9bef

📥 Commits

Reviewing files that changed from the base of the PR and between dd6c726 and 26f4413.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/cron/discount-codes/create/route.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/web/app/(ee)/api/cron/discount-codes/create/route.ts

📝 Walkthrough

Walkthrough

The discount code cron POST route now detects a specific "This application does not have the required permissions" error, logs it at warning level via logAndRespond, and returns early instead of rethrowing.

Changes

Discount Code Cron Permission Error Handling

Layer / File(s) Summary
Permission error handling with early exit
apps/web/app/(ee)/api/cron/discount-codes/create/route.ts
The POST route's catch block adds a conditional that matches the "This application does not have the required permissions" error message, calls logAndRespond with logLevel: "warn", and returns early rather than throwing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • dubinc/dub#3985: Touches the discount-code creation flow and modifies createDiscountCode error/rollback behavior.

Suggested reviewers

  • steven-tey

Poem

🐰 In the cron where codes are made,
A missing scope causes dismay,
We whisper warnings, skip the fight,
And let the job rest for the night. 🌙

🚥 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 and concisely summarizes the main change: handling Stripe permission errors in a discount code cron job by skipping instead of failing.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 fix-discount-code

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/app/`(ee)/api/cron/discount-codes/create/route.ts:
- Around line 101-104: The permission-check branch currently assumes caught
errors are Error objects and calls error.message.includes(...), which can throw
for non-Error throws; update the catch block in route.ts to first guard the
check (e.g., use "error instanceof Error && error.message.includes(...)" or
verify typeof error === 'object' && 'message' in error) before calling includes,
so non-Error values (strings/plain objects) won't cause a new exception and the
original error handling logic (the permission branch and fallback) remains
intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4c27a1e8-04e0-4dd6-a2e0-b6dae0c2a93d

📥 Commits

Reviewing files that changed from the base of the PR and between 1392b11 and dd6c726.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/cron/discount-codes/create/route.ts

Comment thread apps/web/app/(ee)/api/cron/discount-codes/create/route.ts
@devkiran
devkiran merged commit 0a24bb4 into main Jun 5, 2026
11 checks passed
@devkiran
devkiran deleted the fix-discount-code branch June 5, 2026 06:36
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.

1 participant