I've tried to find a good solution for adding errors to an bacon.js EventStream - and propagating them. All this because I wan't to handle the errors later possibly at multiple clients. I've found a hack with flatMap but it's a ... hack:
var streamWithPossibleProblems = bus.flatMap(function(v) {
if (v == "problem") {
return Bacon.sequentially(0, [new Bacon.Error("Error to be reported later")])
}
return v
});
You can just return the Bacon.Error
directly from flatMap
:
var streamWithPossibleProblems = bus.flatMap(function(v) {
if (v == "problem") {
return new Bacon.Error("Error to be reported later")
}
return v
});