ExpressJS / NodeJS / Promises: Return early from promise chain
<p>When I get a post request on the server to create a new game, I perform a couple of queries. First, I search if the user is already in a game, returning the game if so. Otherwise, I search for an open game in which someone is waiting for an opponent and return that game if so. Finally, if no game of the above states are found, I create a new game and return that. So my code looks something like this:</p>

<pre><code>.post( function(req, res, next){

  ...findUsersExistingGame...

  .then(function(game){
    if(game){ return res.send(game); }
    else{
        return ...findUserWaitingForOpponentsGame...
    }
  }
  .then(function(game){
    if(game){ return res.send(game); }
    else{
        return ...createNewGame...
    }
  })
  .then(function(game){
        return res.send(game);
  })
  .catch(function(err){
       return next(err);
  });
</code></pre>

<p>I will eventually refactor each function into helper functions for better readability, but I need to figure out the chaining first. My question is, if I find a game early in the promise chain (i.e. there's either a user's existing game or another user who is waiting for an opponent) then I return res.send(game); However, the third .then will throw an error because my previous .then() statement returned undefined. How do I return early out of the promise chain if I want to do a  res.send(game)? </p>

<p>Option 1: I've seen proposals to throw an error and catch it explicitly, but that feels fundamentally wrong, using errors to control flow that is. </p>

<p>Option 2: Instead of chaining promises, I could do something like this, but this resembles "promise / callback hell":</p>

<pre><code>.post( function(req, res, next){

  ...findUsersExistingGame...

  .then(function(game){
    if(game){ return res.send(game); }
    else{
        ...findUserWaitingForOpponentsGame...
        .then(function(game){
            if(game){ return res.send(game); }
            else{
                return ...createNewGame...
                .then(function(game){
                    return res.send(game);
                });
            }
        })
    }
  }
</code></pre>

<p>Is there another way (preferably in ES5 since I'm still trying to understand promises fundamentally, but ES6 answers welcome as well)?</p>