@@ -34,25 +34,20 @@ export interface ClerkErrorParams {
3434const __DEV__ = true ;
3535
3636export class ClerkError extends Error {
37+ static name = 'ClerkError' ;
3738 readonly clerkError = true as const ;
38- readonly name : string = 'ClerkError' ;
3939 readonly code : string ;
4040 readonly longMessage : string | undefined ;
4141 readonly docsUrl : string | undefined ;
4242 readonly cause : Error | undefined ;
4343
44- constructor ( opts : ClerkErrorParams ) {
45- const formatMessage = ( msg : string , code : string , docsUrl : string | undefined ) => {
46- msg = `${ this . name } : ${ msg . trim ( ) } \n\n(code="${ code } ")\n\n` ;
47- if ( __DEV__ ) {
48- msg += `\n\nDocs: ${ docsUrl } ` ;
49- }
50- return msg ;
51- } ;
44+ get name ( ) {
45+ return this . constructor . name ;
46+ }
5247
53- super ( formatMessage ( opts . message , opts . code , opts . docsUrl ) , { cause : opts . cause } ) ;
48+ constructor ( opts : ClerkErrorParams ) {
49+ super ( new . target . formatMessage ( new . target . name , opts . message , opts . code , opts . docsUrl ) , { cause : opts . cause } ) ;
5450 Object . setPrototypeOf ( this , ClerkError . prototype ) ;
55-
5651 this . code = opts . code ;
5752 this . docsUrl = opts . docsUrl ;
5853 this . longMessage = opts . longMessage ;
@@ -62,6 +57,16 @@ export class ClerkError extends Error {
6257 public toString ( ) {
6358 return `[${ this . name } ]\nMessage:${ this . message } ` ;
6459 }
60+
61+ protected static formatMessage ( name : string , msg : string , code : string , docsUrl : string | undefined ) {
62+ console . log ( '?here2' ) ;
63+
64+ msg = `${ name } : ${ msg . trim ( ) } \n\n(code="${ code } ")\n\n` ;
65+ if ( __DEV__ && docsUrl ) {
66+ msg += `\n\nDocs: ${ docsUrl } ` ;
67+ }
68+ return msg ;
69+ }
6570}
6671
6772/**
0 commit comments