[GH-ISSUE #8264] Feature: Expose unified error code object for Core and Plugins #11035

Open
opened 2026-04-13 07:24:49 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @Wadiou on GitHub (Mar 1, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8264

Originally assigned to: @himself65 on GitHub.

Is this suited for github?

  • Yes, this is suited for github

There is no unified way to extract all better-auth error codes (core + plugins) for i18n/error handling.

Manually aggregating them exposes several DX problems:

  1. Inconsistent access: Some plugins export constants directly, while others require instantiating the plugin to access $ERROR_CODES.
  2. Missing package.json exports: Plugins like api-key and captcha cannot be imported at all due to missing exports definitions (resulting in a Cannot find module error).

Describe the solution you'd like

A built-in utility or function that dynamically returns a single object containing all possible error codes based on the provided better-auth configuration (including core and all active plugins).

Describe alternatives you've considered

Manually aggregating errors by importing them piece-by-piece from the core and each plugin:

import { BASE_ERROR_CODES } from "@better-auth/core/error";
import { admin } from "better-auth/plugins/admin";
// import { apiKey } from "better-auth/plugins/api-key"; // ERROR: Cannot find module

export const ALL_ERROR_CODES = {
  ...BASE_ERROR_CODES,
  ...admin().$ERROR_CODES, 
  // ...apiKey().$ERROR_CODES // Broken due to missing package exports
};
Originally created by @Wadiou on GitHub (Mar 1, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8264 Originally assigned to: @himself65 on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. There is no unified way to extract all `better-auth` error codes (core + plugins) for i18n/error handling. Manually aggregating them exposes several DX problems: 1. **Inconsistent access:** Some plugins export constants directly, while others require instantiating the plugin to access `$ERROR_CODES`. 2. **Missing package.json exports:** Plugins like `api-key` and `captcha` cannot be imported at all due to missing `exports` definitions (resulting in a `Cannot find module` error). ### Describe the solution you'd like A built-in utility or function that dynamically returns a single object containing all possible error codes based on the provided `better-auth` configuration (including core and all active plugins). ### Describe alternatives you've considered Manually aggregating errors by importing them piece-by-piece from the core and each plugin: ```typescript import { BASE_ERROR_CODES } from "@better-auth/core/error"; import { admin } from "better-auth/plugins/admin"; // import { apiKey } from "better-auth/plugins/api-key"; // ERROR: Cannot find module export const ALL_ERROR_CODES = { ...BASE_ERROR_CODES, ...admin().$ERROR_CODES, // ...apiKey().$ERROR_CODES // Broken due to missing package exports };
GiteaMirror added the devtoolscore labels 2026-04-13 07:24:49 -05:00
Author
Owner

@himself65 commented on GitHub (Mar 1, 2026):

Related: https://github.com/better-auth/better-auth/pull/7714

<!-- gh-comment-id:3980567928 --> @himself65 commented on GitHub (Mar 1, 2026): Related: https://github.com/better-auth/better-auth/pull/7714
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#11035