subclass-error
Workaround for subclassing errors. Both instanceof and stack are functional.
Use:
$ npm install subclass-error
var SubclassError = ; var ClientError = ;var ForbiddenError = ; var clientErr = ; clientErr instanceof Error // trueclientErr instanceof ClientError // trueclientErr instanceof ForbiddenError // falseclientErrstatusCode // 400 var forbidErr = ; forbidErr instanceof Error // trueforbidErr instanceof ClientError // trueforbidErr instanceof ForbiddenError // trueforbidErrstatusCode // 403 { throw "wow, much forbidden, very subclass";} ;/* ForbiddenError: wow, much forbidden, very subclass at hungry (filePath:19:8) etc expected stack*/
SubclassError(name, [error, properties])
Creates a new subclass of 'error' (if specified) or Error (by default). The instances of the new subclass will have the same properties as those provided in the optional 'properties' parameter.
Notes:
I didn't find any other workaround in which both 'instanceof' and 'stack' work as you would expect, so I ended up creating this.
License
MIT