I am trying to throw and then catch a custom error in a Bluebird promise chain, but I can\'t get it to catch the custom error. For example:
function login(re
Bluebird distinguishes error constructors from predicate functions in a catch by their inheritance:
For a parameter to be considered a type of error that you want to filter, you need the constructor to have its
.prototype
property beinstanceof Error
.Such a constructor can be minimally created like so:
function MyCustomError() {} MyCustomError.prototype = Object.create(Error.prototype);
You will need to do the same for your LoginError
.
Or if you're using ES6, then class LoginError extends Error {}
.