-
Notifications
You must be signed in to change notification settings - Fork 405
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
Changes from all commits
784c38b
1f6771e
25126a6
59df41c
ccb61e3
File filter
Filter by extension
Conversations
Jump to
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>; | ||
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