Some recent discussion in the WatchMeCode slack spawned a bit of research into creating custom errors through factory methods, while keeping the stack trace for those errors clean, in Node.js
After a bit of digging, I found a good solution using Node’s Error.captureStackTrace method, and recorded a quick screencast to highlight it’s use.
The Sample Code
If you’d like to run the sample code that I showed in this screencast, you can grab it from this gist.
And if you would like to read up on errors further, check out these additional resources: