Skip to content

Fix stripe webhook#73

Merged
DavidASix merged 9 commits into
stagingfrom
fix-stripe-webhook
Nov 28, 2025
Merged

Fix stripe webhook#73
DavidASix merged 9 commits into
stagingfrom
fix-stripe-webhook

Conversation

@DavidASix

Copy link
Copy Markdown
Owner

Stripe disables webhooks if they fail often (a failure is any response not between 200 - 299).

The webhook was receiving requests from other product subscriptions on my account (which obviously didn't have customer IDs in the pg db, I need to make a separate stripe account for bragfeed).

To mitigate this, the webhook now almost always returns a 200 of some kind so stripe know we got it.

Copilot AI review requested due to automatic review settings November 28, 2025 17:03

Copilot AI 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.

Pull request overview

This PR fixes Stripe webhook handling to prevent webhook disablement due to frequent failures. The solution introduces a HandledError class to distinguish expected business logic errors (which should return 200 to Stripe) from unexpected technical failures (which should trigger retries).

Key Changes:

  • Introduces HandledError class for expected error conditions that shouldn't trigger Stripe retries
  • Converts multiple error throws to use HandledError for missing customer IDs, missing metadata, and other expected validation failures
  • Changes HTTP status codes from 500 to 202 for both handled and unhandled errors in the webhook response

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/app/api/purchases/webhook/route.ts Outdated
Comment thread src/app/api/purchases/webhook/route.ts
Comment thread src/app/api/purchases/webhook/route.ts
Comment thread src/app/api/purchases/webhook/route.ts Outdated
Comment thread src/app/api/purchases/webhook/route.ts Outdated
Comment thread src/app/api/purchases/webhook/route.ts Outdated
DavidASix and others added 3 commits November 28, 2025 12:08
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@DavidASix
DavidASix changed the base branch from main to staging November 28, 2025 17:14
@DavidASix
DavidASix merged commit b73e6b0 into staging Nov 28, 2025
3 checks passed
@DavidASix
DavidASix deleted the fix-stripe-webhook branch November 28, 2025 17:14
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