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:
var promise = database.getUserCookies(user)
.then(function (data){
return proxy.search(data);
})
.fail(function (data) {
if (data.rejected === 302) {
var relogin = database.fetchAuth(data)
.then(function (data) {
return proxy.login(data)
})
.then(function (data){
return database.saveCookies(data);
})
.then(function (data){
//Restart the promise from the top.
})
}
})
.then(function (data){
return responser.search(data);
})