Assume a function returning a custom promise. For the sake of this example, lets just assume a custom promise is needed:

**(Note: the environment is AngularJS [i.e. 1.x] that does ES5)**

```
function doMyFunction() {
   var d = $q.defer();
   do1()
   .then (function () { return do2(); }) //P1
   .then (function () { return do3(); }) // P2
   .then {function () {console.log ("All good"); d.resolve(true); return d.promise;}) // P3
   .catch (function () { 
        console.log ("Oh no"); 
        fallback1()
        .then (function () {
             console.log ("Ah this fallback1 worked");
             d.resolve(true);
             return d.promise;
        }, function () { 
            console.log ("Oh no, fallback failed, do I have to go through nested hell to now try fallback 2?");
           d.resolve(false);
           return d.promise;
       });
     return d.promise;
}

```

As describe above, I am trying to try different approaches in sequence, only if the former approach fails. 

If I try and flatten it like so:

```
// lets start from the last promise above

.then {function () {console.log ("All good"); d.resolve(true); return d.promise;}) // P3
.catch (function () { return fallback1(); })
.then (function () { d.resolve(true); return d.promise; }) // P4
.catch (function () {})

```

This doesn't really work, because P4 is executed when P3 succeeds as well.

What is a good approach to handle a case where I need to try multiple promise based functions in sequence and only if the previous one fails?

Also, I'm not sure if I can really do `.then().catch().then().catch()`

Is there a clean approach to avoid nesting hell in such situations?