I\'m using Nodejs and Q to run a sequence of asynchronous functions. If one fails i\'d like to run another function and then start the sequence again. Heres it is as is:
You need to wrap it in a function that you can call again. A promise by itself cannot be "restarted".
var promise = (function trySearch() {
return database.getUserCookies(user)
.then(proxy.search)
.fail(function(err) {
if (err.rejected === 302) { // only when missing authentication
return database.fetchAuth(data)
// ^^^^^^
.then(proxy.login)
.then(database.saveCookies)
.then(trySearch) // try again
} else
throw err;
})
}())
.then(responser.search)