[PR #7934] [MERGED] chore: use throw APIError.from #33235

Closed
opened 2026-04-17 23:53:26 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7934
Author: @himself65
Created: 2/12/2026
Status: Merged
Merged: 2/12/2026
Merged by: @himself65

Base: canaryHead: himself65/2026/02/12/error


📝 Commits (2)

📊 Changes

7 files changed (+38 additions, -38 deletions)

View changed files

📝 packages/better-auth/src/api/routes/session.ts (+8 -1)
📝 packages/better-auth/src/plugins/anonymous/index.ts (+4 -6)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+1 -1)
📝 packages/better-auth/src/plugins/organization/routes/crud-invites.ts (+4 -6)
📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+5 -9)
📝 packages/better-auth/src/plugins/username/index.ts (+4 -6)
📝 packages/passkey/src/routes.ts (+12 -9)

📄 Description

Summary by cubic

Standardized error handling across auth, org, and passkey routes by throwing APIError.from instead of returning JSON. Errors now carry consistent 4xx/5xx statuses with better logging.

  • Refactors
    • Replaced ctx.json with throw APIError.from in: session refresh, anonymous sign-in, username sign-in, org invite accept/delete, and passkey registration verify.
    • Used APIError.fromStatus("UNAUTHORIZED") when creating an org without a user.
    • Added isAPIError guard in session route to rethrow known errors; others are logged and wrapped as INTERNAL_SERVER_ERROR.
    • Aligned error codes: BASE (FAILED_TO_GET_SESSION/FAILED_TO_CREATE_SESSION), ANONYMOUS.COULD_NOT_CREATE_SESSION, ORGANIZATION (INVITATION_NOT_FOUND/ORGANIZATION_NOT_FOUND), PASSKEY (FAILED_TO_VERIFY_REGISTRATION/CHALLENGE_NOT_FOUND).
    • Fixed org invitation test to expect a non-null accept result.

Written for commit 347ac02867. 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/7934 **Author:** [@himself65](https://github.com/himself65) **Created:** 2/12/2026 **Status:** ✅ Merged **Merged:** 2/12/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2026/02/12/error` --- ### 📝 Commits (2) - [`2fe2147`](https://github.com/better-auth/better-auth/commit/2fe2147ac6447555c8f8b27d25a131f2f4e89041) chore: use throw APIError.from - [`347ac02`](https://github.com/better-auth/better-auth/commit/347ac02867da0b16fb55c3f95679df47762718c1) fix: test ### 📊 Changes **7 files changed** (+38 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/session.ts` (+8 -1) 📝 `packages/better-auth/src/plugins/anonymous/index.ts` (+4 -6) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/organization/routes/crud-invites.ts` (+4 -6) 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+5 -9) 📝 `packages/better-auth/src/plugins/username/index.ts` (+4 -6) 📝 `packages/passkey/src/routes.ts` (+12 -9) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Standardized error handling across auth, org, and passkey routes by throwing APIError.from instead of returning JSON. Errors now carry consistent 4xx/5xx statuses with better logging. - **Refactors** - Replaced ctx.json with throw APIError.from in: session refresh, anonymous sign-in, username sign-in, org invite accept/delete, and passkey registration verify. - Used APIError.fromStatus("UNAUTHORIZED") when creating an org without a user. - Added isAPIError guard in session route to rethrow known errors; others are logged and wrapped as INTERNAL_SERVER_ERROR. - Aligned error codes: BASE (FAILED_TO_GET_SESSION/FAILED_TO_CREATE_SESSION), ANONYMOUS.COULD_NOT_CREATE_SESSION, ORGANIZATION (INVITATION_NOT_FOUND/ORGANIZATION_NOT_FOUND), PASSKEY (FAILED_TO_VERIFY_REGISTRATION/CHALLENGE_NOT_FOUND). - Fixed org invitation test to expect a non-null accept result. <sup>Written for commit 347ac02867da0b16fb55c3f95679df47762718c1. 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-17 23:53:26 -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#33235