File tree Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change 234
234
}
235
235
236
236
function createErrorClass ( className ) {
237
- var ExtendedError = function ( message ) {
238
- Error . call ( this , message ) ;
239
- this . name = className ;
237
+ function ExtendedError ( message ) {
238
+ var instance = new Error ( message ) ;
239
+ instance . name = className ;
240
+ Object . setPrototypeOf ( instance , Object . getPrototypeOf ( this ) ) ;
241
+ if ( Error . captureStackTrace ) {
242
+ Error . captureStackTrace ( instance , ExtendedError )
243
+ }
244
+ return instance ;
240
245
} ;
241
- ExtendedError . prototype = Object . create ( Error . prototype ) ;
242
- ExtendedError . prototype . constructor = ExtendedError ;
246
+ ExtendedError . prototype = Object . create ( Error . prototype , {
247
+ constructor : {
248
+ value : Error ,
249
+ enumerable : false ,
250
+ writeable : true ,
251
+ configurable : true ,
252
+ } ,
253
+ } ) ;
243
254
244
255
return ExtendedError ;
245
256
}
Original file line number Diff line number Diff line change @@ -227,6 +227,7 @@ describe('search', function() {
227
227
assert ( e . message . search (
228
228
'expected argument 1 to be type string,array,object'
229
229
) , e . message ) ;
230
+ assert . strictEqual ( e . name , 'TypeMismatchError' ) ;
230
231
assert ( e . message . search ( 'received type null' ) , e . message ) ;
231
232
}
232
233
}
You can’t perform that action at this time.
0 commit comments