catchmap
Utility for removing tedious error checking.
Works great with promises and blends nicely with co and koa.
In short, catchmap(...errors)
creates a function (err) {}
that will devour matching errors and re-throw the rest.
Example
catchmap(...)
takes care of checking error types and Error.code
for you.
// Clear and readable ...
// Yawn, do I have to read all this error checking? ...
Errors can also be mapped to values using catchmap(...).to(value)
.
Optimize it a bit by sharing instances of catchmap
.
var allowAcceptableError = // allowAcceptableError is equivalent with// catchmap('ENOENT',SyntaxError).to(undefined) ...