When my system is creating errors, those are collected and finally sent to a ticket API. All errors are grouped by their type of priority. So, if two different error types are thrown, two tickets should be sent.
Looks like:
var tickets = [{
type: 'validation',
component: 1,
time: '2016-04-13T10:26:41.420Z',
messages: [ [Object], [Object], [...] ]
}, {
type: 'fatal',
component: 1,
time: '2016-04-13T10:26:41.420Z',
messages: [ [Object] ]
}];
Every object within that array should be sent after another, delayed by 2 seconds. sendToTicketAPI() returns a Promise and I also want to return a promise when all tickets are sent. My thought was, I could resolve/reject it with .onEnd/.onError.
Code is:
var Bacon = require('baconjs'); //v0.7.71
createTicketWrapper(msg, fnResolve, fnReject) {
Bacon
.fromArray(tickets)
.bufferingThrottle(2000)
.flatMap(function (ticket) {
return sendToTicketAPI(ticket)
.then(function () {
return ticket;
});
})
.onError(function (err) {
console.error('Unexpected error msg', err);
if (fnReject)
fnReject();
})
.onEnd(function () {
if (fnResolve)
fnResolve()
});
}
But I'm getting:
[TypeError: Bacon.fromArray(...).bufferingThrottle(...).flatMap(...).onError(...).onEnd is not a function]
I don't understand why .onEnd is not a function!? Maybe another approach?