File tree 2 files changed +17
-4
lines changed
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");
109
109
logger . error ( e ) ;
110
110
111
111
///////////////////////////
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> {
276
276
}
277
277
278
278
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 ) ;
281
284
Object . assign ( newError , error ) ;
282
- const propertyNames = Object . getOwnPropertyNames ( newError ) ;
283
- for ( const propName of propertyNames ) {
285
+
286
+ for ( const propName of errorProperties ) {
284
287
const propDesc = Object . getOwnPropertyDescriptor ( newError , propName ) ;
285
288
if ( propDesc ) {
286
289
propDesc . writable = true ;
You can’t perform that action at this time.
0 commit comments