Uses promises.
Something like:
doSomething().then(
function() {
doSomethingElse().then(
function(){
doYetAnotherThing()
})
});
return 42;
where doSomething, doSomethingElse and doYetAnotherThing represent the individual steps that could 'break' (where break now means 'return a promise that is marked as failed). Each of them should return a promise. To make the code flatter you could alternatively do promise-chaining (here's a good video, in the context of Angular but you can ignore that part)