Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions packages/clerk-js/src/core/signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,38 @@ function errorsToParsedErrors(error: unknown): Errors {
captcha: null,
legalAccepted: null,
},
raw: [],
global: [],
raw: null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate that this is the case, but we need to update the default errors in the state proxy in clerk-react as well 😭

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!
Ill try to prioritize some tests to catch these sooner and a (potential) refactor later. Fixing...

global: null,
};

if (!error) {
return parsedErrors;
}

if (!isClerkAPIResponseError(error)) {
parsedErrors.raw.push(error);
parsedErrors.global.push(error);
parsedErrors.raw = [error];
parsedErrors.global = [error];
return parsedErrors;
}

parsedErrors.raw.push(...error.errors);

error.errors.forEach(error => {
if (parsedErrors.raw) {
parsedErrors.raw.push(error);
} else {
parsedErrors.raw = [error];
}

if ('meta' in error && error.meta && 'paramName' in error.meta) {
const name = snakeToCamel(error.meta.paramName);
parsedErrors.fields[name as keyof typeof parsedErrors.fields] = error;
return;
}

parsedErrors.global.push(error);
if (parsedErrors.global) {
parsedErrors.global.push(error);
} else {
parsedErrors.global = [error];
}
});

return parsedErrors;
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ interface FieldErrors {

export interface Errors {
fields: FieldErrors;
raw: unknown[];
global: unknown[]; // does not include any errors that could be parsed as a field error
raw: unknown[] | null;
global: unknown[] | null;
}

export interface SignInSignal {
Expand Down
Loading