1 # Delegates to `succ` on sucecss or to `fail` on error
2 # ex: Thing.load 123, iferr cb, (thing) -> ...
3 iferr = (fail, succ) -> (err, a...) ->
7 # Like iferr, but also catches errors thrown from `succ` and passes to `fail`
8 tiferr = (fail, succ) -> iferr fail, (a...) ->
10 catch err then fail err
12 # Delegate to the success function on success, or throw the error otherwise
13 # ex: Thing.load 123, throwerr (thing) -> ...
14 throwerr = iferr.bind null, (err) -> throw err
16 # Prints errors when one is passed, or does nothing otherwise
17 # ex: thing.save printerr
18 printerr = iferr (err) -> console.error err.stack or err
20 module.exports = exports = iferr
22 exports.tiferr = tiferr
23 exports.throwerr = throwerr
24 exports.printerr = printerr