Initial Commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { defineCodes } from "@suaveplan/error";
|
||||
|
||||
/**
|
||||
* Stable error codes for `@suaveplan/react-auth-whitelabel`.
|
||||
*
|
||||
* Codes are grouped under the `REACT_AUTH_WL` namespace and registered at
|
||||
* module load time via `defineCodes`. The registry is the single source
|
||||
* of truth for error-code identity across the white-label auth surface —
|
||||
* every thrown `ReactAuthWhitelabelError` carries one of these strings
|
||||
* as its `.code`.
|
||||
*
|
||||
* Codes:
|
||||
* - `BRANDING_FETCH_FAILED` — `BrandingProvider`'s configured fetch
|
||||
* returned a non-ok response (or threw). The error surfaces on the
|
||||
* context's `error` field; consumers can branch on `.code` to render a
|
||||
* tenant-specific fallback.
|
||||
* - `BRANDING_INVALID_PAYLOAD` — the fetched branding payload failed
|
||||
* `TenantBrandingSchema.safeParse(...)`. The error carries a Zod issue
|
||||
* tree in `context.issues`.
|
||||
* - `AUTH_NETWORK_FAILED` — an `AuthProvider` verb's underlying `fetch`
|
||||
* threw (offline / DNS / CORS preflight failure).
|
||||
* - `AUTH_REJECTED` — the backend responded with `ok: false`; the
|
||||
* parsed response body's `message` field, when present, is forwarded
|
||||
* in the error's message-args context.
|
||||
* - `MISSING_RESET_TOKEN` — `PasswordResetForm` was rendered in
|
||||
* `mode="confirm"` without a `token` prop. The form blocks submission
|
||||
* and surfaces the error inline.
|
||||
* - `PROVIDER_OUTSIDE_TREE` — `useAuth()` / `useBranding()` was called
|
||||
* without an enclosing provider. The error carries `context.hook` so
|
||||
* logs identify the offending call site.
|
||||
*/
|
||||
export const REACT_AUTH_WL_CODES = defineCodes("REACT_AUTH_WL", [
|
||||
"BRANDING_FETCH_FAILED",
|
||||
"BRANDING_INVALID_PAYLOAD",
|
||||
"AUTH_NETWORK_FAILED",
|
||||
"AUTH_REJECTED",
|
||||
"MISSING_RESET_TOKEN",
|
||||
"PROVIDER_OUTSIDE_TREE",
|
||||
] as const);
|
||||
|
||||
export type ReactAuthWhitelabelCode =
|
||||
(typeof REACT_AUTH_WL_CODES)[keyof typeof REACT_AUTH_WL_CODES];
|
||||
Reference in New Issue
Block a user