[PR #6678] [CLOSED] fix(stripe): improve error handling and centralize error management #23719

Closed
opened 2026-04-15 21:56:03 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6678
Author: @bytaesu
Created: 12/10/2025
Status: Closed

Base: canaryHead: 2025-12-11/fix/stripe-error-handling


📝 Commits (3)

  • 40f7ed0 separate error codes into new file
  • eb8cc47 refactor error handling and centralize error management
  • 51afd00 test: update error messages

📊 Changes

5 files changed (+60 additions, -50 deletions)

View changed files

packages/stripe/src/error-codes.ts (+23 -0)
📝 packages/stripe/src/index.ts (+1 -14)
📝 packages/stripe/src/middleware.ts (+6 -4)
📝 packages/stripe/src/routes.ts (+27 -29)
📝 packages/stripe/src/stripe.test.ts (+3 -3)

📄 Description

Summary by cubic

Centralized Stripe error codes and tightened error handling in middleware and webhook routes to return consistent, clear messages. This improves reliability of subscription and billing flows and makes failures easier to debug.

  • Refactors

    • Introduced STRIPE_ERROR_CODES in packages/stripe/src/error-codes.ts and removed inline definitions.
    • Standardized APIError messages across middleware and routes using constants.
    • Updated tests to match new messages.
  • Bug Fixes

    • Webhook: validate request body, stripe-signature, and secret; unify constructEvent errors.
    • Return specific messages for customer not found and billing portal creation failures.
    • Enforce referenceId authorization and return consistent UNAUTHORIZED messages.

Written for commit 51afd00088. Summary will update automatically 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/6678 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 12/10/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `2025-12-11/fix/stripe-error-handling` --- ### 📝 Commits (3) - [`40f7ed0`](https://github.com/better-auth/better-auth/commit/40f7ed00afadb4d44a5f3b73b354ff3d47acc5b5) separate error codes into new file - [`eb8cc47`](https://github.com/better-auth/better-auth/commit/eb8cc47685668049751ba83c67c7ceebc16113eb) refactor error handling and centralize error management - [`51afd00`](https://github.com/better-auth/better-auth/commit/51afd0008897aa380329c566a855b0fd1c45b7c6) test: update error messages ### 📊 Changes **5 files changed** (+60 additions, -50 deletions) <details> <summary>View changed files</summary> ➕ `packages/stripe/src/error-codes.ts` (+23 -0) 📝 `packages/stripe/src/index.ts` (+1 -14) 📝 `packages/stripe/src/middleware.ts` (+6 -4) 📝 `packages/stripe/src/routes.ts` (+27 -29) 📝 `packages/stripe/src/stripe.test.ts` (+3 -3) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Centralized Stripe error codes and tightened error handling in middleware and webhook routes to return consistent, clear messages. This improves reliability of subscription and billing flows and makes failures easier to debug. - **Refactors** - Introduced STRIPE_ERROR_CODES in packages/stripe/src/error-codes.ts and removed inline definitions. - Standardized APIError messages across middleware and routes using constants. - Updated tests to match new messages. - **Bug Fixes** - Webhook: validate request body, stripe-signature, and secret; unify constructEvent errors. - Return specific messages for customer not found and billing portal creation failures. - Enforce referenceId authorization and return consistent UNAUTHORIZED messages. <sup>Written for commit 51afd0008897aa380329c566a855b0fd1c45b7c6. Summary will update automatically 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-15 21:56:03 -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#23719