Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 470
feat(clerk-js): Type errors.global as ClerkGlobalHookError#7174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
784c38b1f6771e25126a659df41cccb61e3File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@clerk/clerk-js': minor | ||
| '@clerk/shared': minor | ||
| --- | ||
| [Experimental] Add types for errors used in new custom flow APIs |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { isClerkApiResponseError } from './clerkApiResponseError'; | ||
| import type { ClerkError } from './clerkError'; | ||
| import { isClerkRuntimeError } from './clerkRuntimeError'; | ||
| /** | ||
| * Creates a ClerkGlobalHookError object from a ClerkError instance. | ||
| * It's a wrapper for all the different instances of Clerk errors that can | ||
| * be returned when using Clerk hooks. | ||
| */ | ||
| export function createClerkGlobalHookError(error: ClerkError) { | ||
| const predicates = { | ||
| isClerkApiResponseError, | ||
| isClerkRuntimeError, | ||
| } as const; | ||
| for (const [name, fn] of Object.entries(predicates)) { | ||
| Object.assign(error, { [name]: fn }); | ||
| } | ||
| return error as ClerkError & typeof predicates; | ||
| } | ||
Comment on lines
+10
to
+21
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify predicate binding and avoid mutating the input parameter. The function mutates the input If the intent is to provide predicate methods that check the error itself, bind them by wrapping in closures: export function createClerkGlobalHookError(error: ClerkError) {
const predicates = {
- isClerkApiResponseError,- isClerkRuntimeError,+ isClerkApiResponseError: () => isClerkApiResponseError(error),+ isClerkRuntimeError: () => isClerkRuntimeError(error),
} as const;
- for (const [name, fn] of Object.entries(predicates)) {- Object.assign(error, { [name]: fn });- }-- return error as ClerkError & typeof predicates;+ return Object.assign({}, error, predicates) as ClerkError & typeof predicates;
}This eliminates mutation and provides a cleaner API where Based on coding guidelines: "Prefer readonly properties for immutable data structures." 🤖 Prompt for AI Agents | ||
| export type ClerkGlobalHookError = ReturnType<typeof createClerkGlobalHookError>; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import type { ClerkGlobalHookError } from '../errors/globalHookError'; | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| import type { SignInFutureResource } from './signInFuture'; | ||
| import type { SignUpFutureResource } from './signUpFuture'; | ||
| @@ -79,8 +80,9 @@ export interface Errors { | ||
| raw: unknown[] | null; | ||
| /** | ||
| * Parsed errors that are not related to any specific field. | ||
| * Does not include any errors that could be parsed as a field error | ||
| */ | ||
| global: unknown[] | null; // does not include any errors that could be parsed as a field error | ||
| global: ClerkGlobalHookError[] | null; | ||
| } | ||
| /** | ||
| @@ -143,6 +145,7 @@ export interface State { | ||
| * An alias for `effect()` from `alien-signals`, which can be used to subscribe to changes from Signals. | ||
| * | ||
| * @see https://github.com/stackblitz/alien-signals#usage | ||
| * | ||
| * @experimental This experimental API is subject to change. | ||
| */ | ||
| __internal_effect: (callback: () => void) => () => void; | ||
| @@ -152,6 +155,7 @@ export interface State { | ||
| * its dependencies change. | ||
| * | ||
| * @see https://github.com/stackblitz/alien-signals#usage | ||
| * | ||
| * @experimental This experimental API is subject to change. | ||
| */ | ||
| __internal_computed: <T>(getter: (previousValue?: T) => T) => () => T; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore the raw API errors array
Errors.rawis documented (packages/shared/src/types/state.ts Line 74) as “The raw, unparsed errors from the Clerk API.” Storing the aggregateClerkAPIResponseErrorhere drops the per-error payload consumers rely on. Keeprawas the API error list.Apply this diff to preserve the original payload:
🤖 Prompt for AI Agents