[PR #7087] [MERGED] fix(stripe): Improve error handling and subscriptionSuccess route #15313

Closed
opened 2026-04-13 09:57:39 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7087
Author: @bytaesu
Created: 1/1/2026
Status: Merged
Merged: 1/1/2026
Merged by: @bytaesu

Base: canaryHead: 2026-01-02/refactor/stripe-plugin


📝 Commits (5)

  • 1a79985 refactor: improve error handling
  • f1fa5f7 refactor: use subscriptionItem
  • a534d63 refactor: subscriptionSuccess route
  • 5e9b338 refactor: use isActiveOrTrialing helper
  • fd25a8b bad_request to internal_server_error

📊 Changes

6 files changed (+170 additions, -144 deletions)

View changed files

📝 packages/stripe/src/error-codes.ts (+9 -0)
📝 packages/stripe/src/hooks.ts (+26 -18)
📝 packages/stripe/src/index.ts (+1 -14)
📝 packages/stripe/src/middleware.ts (+8 -9)
📝 packages/stripe/src/routes.ts (+123 -100)
📝 packages/stripe/src/stripe.test.ts (+3 -3)

📄 Description

  • Improves error handling
  • Refactors subscription item handling for cleaner array management
  • Refactors the subscriptionSuccess route to remove non-null assertions

Summary by cubic

Refactors the Stripe plugin to centralize error handling and make subscription item logic safer, reducing crashes and improving reliability in webhooks, billing portal, and subscription success flow.

  • Refactors

    • Centralized STRIPE_ERROR_CODES and switched to APIError.from across middleware and routes.
    • Removed non-null assertions; added safe subscriptionItem checks and early returns in hooks and subscriptionSuccess.
    • Simplified webhook payload handling and event construction with clearer logs.
    • Adopted isActiveOrTrialing helper for status checks; minor readability improvements.
  • Bug Fixes

    • Prevented crashes when subscriptions have no items.
    • Returned specific errors for missing subscription, customer, signature, webhook secret, and failed event construction.
    • subscriptionSuccess now skips updates when already active/trialing and handles missing customer IDs gracefully.
    • Updated tests to match new error messages.

Written for commit fd25a8b961. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7087 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 1/1/2026 **Status:** ✅ Merged **Merged:** 1/1/2026 **Merged by:** [@bytaesu](https://github.com/bytaesu) **Base:** `canary` ← **Head:** `2026-01-02/refactor/stripe-plugin` --- ### 📝 Commits (5) - [`1a79985`](https://github.com/better-auth/better-auth/commit/1a799859ef754a882f1bd4f3c099517d81b2e02d) refactor: improve error handling - [`f1fa5f7`](https://github.com/better-auth/better-auth/commit/f1fa5f72cb7cb7a0ce15df167446e380a36fc81e) refactor: use subscriptionItem - [`a534d63`](https://github.com/better-auth/better-auth/commit/a534d63bd08fbc93b40642eb05eb4ddca0ed18e7) refactor: subscriptionSuccess route - [`5e9b338`](https://github.com/better-auth/better-auth/commit/5e9b3385d0aa5e6bec812b0bf50a7afa98d8fcbc) refactor: use isActiveOrTrialing helper - [`fd25a8b`](https://github.com/better-auth/better-auth/commit/fd25a8b96149563b7a5a7da73a97a1d17a892ffd) bad_request to internal_server_error ### 📊 Changes **6 files changed** (+170 additions, -144 deletions) <details> <summary>View changed files</summary> 📝 `packages/stripe/src/error-codes.ts` (+9 -0) 📝 `packages/stripe/src/hooks.ts` (+26 -18) 📝 `packages/stripe/src/index.ts` (+1 -14) 📝 `packages/stripe/src/middleware.ts` (+8 -9) 📝 `packages/stripe/src/routes.ts` (+123 -100) 📝 `packages/stripe/src/stripe.test.ts` (+3 -3) </details> ### 📄 Description - Improves error handling - Refactors subscription item handling for cleaner array management - Refactors the subscriptionSuccess route to remove non-null assertions <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Refactors the Stripe plugin to centralize error handling and make subscription item logic safer, reducing crashes and improving reliability in webhooks, billing portal, and subscription success flow. - **Refactors** - Centralized STRIPE_ERROR_CODES and switched to APIError.from across middleware and routes. - Removed non-null assertions; added safe subscriptionItem checks and early returns in hooks and subscriptionSuccess. - Simplified webhook payload handling and event construction with clearer logs. - Adopted isActiveOrTrialing helper for status checks; minor readability improvements. - **Bug Fixes** - Prevented crashes when subscriptions have no items. - Returned specific errors for missing subscription, customer, signature, webhook secret, and failed event construction. - subscriptionSuccess now skips updates when already active/trialing and handles missing customer IDs gracefully. - Updated tests to match new error messages. <sup>Written for commit fd25a8b96149563b7a5a7da73a97a1d17a892ffd. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 09:57:39 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#15313