File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -109,3 +109,13 @@ const e = createReadonlyError("message", "property");
109109logger . error ( e ) ;
110110
111111///////////////////////////
112+
113+ class CustomError extends Error {
114+ constructor ( message1 : string , message2 : string ) {
115+ super ( message1 ) ;
116+ console . log ( "***" , message1 , message2 ) ;
117+ }
118+ }
119+
120+ const err = new CustomError ( "a" , "b" ) ;
121+ logger . error ( err ) ;
Original file line number Diff line number Diff line change @@ -276,11 +276,14 @@ export class BaseLogger<LogObj> {
276276 }
277277
278278 private _cloneError < T extends Error > ( error : T ) : T {
279- const ErrorConstructor = error . constructor as new ( message ?: string ) => T ;
280- const newError = new ErrorConstructor ( error . message ) ;
279+ const ErrorConstructor = error . constructor as new ( ...args : any [ ] ) => T ;
280+ const errorProperties = Object . getOwnPropertyNames ( error ) ;
281+ const errorArgs = errorProperties . map ( ( propName ) => error [ propName ] ) ;
282+
283+ const newError = new ErrorConstructor ( ...errorArgs ) ;
281284 Object . assign ( newError , error ) ;
282- const propertyNames = Object . getOwnPropertyNames ( newError ) ;
283- for ( const propName of propertyNames ) {
285+
286+ for ( const propName of errorProperties ) {
284287 const propDesc = Object . getOwnPropertyDescriptor ( newError , propName ) ;
285288 if ( propDesc ) {
286289 propDesc . writable = true ;
You can’t perform that action at this time.
0 commit comments