Skip to content
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

fix(shared): Removal of clerkError property #1839

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/empty-donuts-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Revert the removal of the `clerkError` property from `ClerkAPIError` class.
1 change: 1 addition & 0 deletions packages/clerk-js/src/core/resources/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export {
MagicLinkError,
ClerkAPIResponseError,
isClerkRuntimeError,
ClerkRuntimeError,
} from '@clerk/shared';
export type { MetamaskError } from '@clerk/shared';
8 changes: 5 additions & 3 deletions packages/clerk-js/src/core/resources/SignUp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClerkRuntimeError, Poller } from '@clerk/shared';
import { Poller } from '@clerk/shared';
import type {
AttemptEmailAddressVerificationParams,
AttemptPhoneNumberVerificationParams,
Expand Down Expand Up @@ -30,7 +30,7 @@ import {
clerkVerifyEmailAddressCalledBeforeCreate,
clerkVerifyWeb3WalletCalledBeforeCreate,
} from '../errors';
import { BaseResource, SignUpVerifications } from './internal';
import { BaseResource, ClerkRuntimeError, SignUpVerifications } from './internal';

declare global {
interface Window {
Expand Down Expand Up @@ -211,7 +211,9 @@ export class SignUp extends BaseResource implements SignUpResource {
continueSignUp = false,
unsafeMetadata,
emailAddress,
}: AuthenticateWithRedirectParams & { unsafeMetadata?: SignUpUnsafeMetadata }): Promise<void> => {
}: AuthenticateWithRedirectParams & {
unsafeMetadata?: SignUpUnsafeMetadata;
}): Promise<void> => {
const authenticateFn = (args: SignUpCreateParams | SignUpUpdateParams) =>
continueSignUp && this.id ? this.update(args) : this.create(args);

Expand Down
14 changes: 9 additions & 5 deletions packages/shared/src/errors/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export function isKnownError(error: any) {
}

export function isClerkAPIResponseError(err: any): err is ClerkAPIResponseError {
if (err instanceof ClerkAPIResponseError) {
return true;
}

return 'clerkError' in err;
}

Expand All @@ -42,7 +38,7 @@ export function isClerkAPIResponseError(err: any): err is ClerkAPIResponseError
* }
*/
export function isClerkRuntimeError(err: any): err is ClerkRuntimeError {
return err instanceof ClerkRuntimeError;
return 'clerkRuntimeError' in err;
}

export function isMetamaskError(err: any): err is MetamaskError {
Expand All @@ -68,6 +64,8 @@ export function parseError(error: ClerkAPIErrorJSON): ClerkAPIError {
}

export class ClerkAPIResponseError extends Error {
clerkError: true;

status: number;
message: string;

Expand All @@ -80,6 +78,7 @@ export class ClerkAPIResponseError extends Error {

this.status = status;
this.message = message;
this.clerkError = true;
this.errors = parseErrors(data);
}

Expand All @@ -98,6 +97,8 @@ export class ClerkAPIResponseError extends Error {
* throw new ClerkRuntimeError('An error occurred', { code: 'password_invalid' });
*/
export class ClerkRuntimeError extends Error {
clerkRuntimeError: true;

/**
* The error message.
*
Expand All @@ -113,13 +114,15 @@ export class ClerkRuntimeError extends Error {
* @memberof ClerkRuntimeError
*/
code: string;

constructor(message: string, { code }: { code: string }) {
super(message);

Object.setPrototypeOf(this, ClerkRuntimeError.prototype);

this.code = code;
this.message = message;
this.clerkRuntimeError = true;
}

/**
Expand All @@ -142,6 +145,7 @@ export class MagicLinkError extends Error {
Object.setPrototypeOf(this, MagicLinkError.prototype);
}
}

// Check if the error is a MagicLinkError.

export function isMagicLinkError(err: Error): err is MagicLinkError {
Expand Down