title: Chain Angular $http calls properly?
body: <p>I have been reading about $q and promises for days now and I seem to understand it...somewhat. I have the following situation in practice:</p>
  
  <ol>
  <li>An $http request is made and checks whether a subsequent call can be made. </li>
  <li><p>If the first call fails, return "no data", if it succeeds and says a call can be made, the second call is made, if not - "no data" again. If the second call succeeds, it returns data, if not - "no data". It looks like this (approximately, I simplified for general idea, so don't worry about the minor mistakes here):</p>
  
  <pre><code>        return $http.get (something)
              .then(function(allowedAccess){
                  if(allowedAccess){
                      return $http.get (somethingElse)
                          .then( function(result){return {data:result} },
                          function(error){return {data:"n0pe"} }
                      )
                  } else {
                      return {data:"n0pe"}
                  }
              },
              function(){ return {data:"n0pe"} });
  </code></pre></li>
  </ol>
  
  <p>I was told to use $q here. I don't really understand how or why I would. The $http calls are promises already. </p>
  
  <p>If there is a way to make this cleaner, I don't see it. Just got done re-reading this <a href="http://blog.xebia.com/2014/02/23/promises-and-design-patterns-in-angularjs/">post on the subject</a>. Essentially, am I missing something / is there a better way to do this?</p>
  
  <p>Edit: Also just re-read <a href="http://solutionoptimist.com/2013/12/27/javascript-promise-chains-2/">a tutorial on chaining promises</a> - it doesn't handle call failures at all. Basically posting this as due diligence. </p>
  
  <p>Edit 2: This is more of an elaborate on the theory I am asking about, excerpt from the first article:</p>
  
  <blockquote>
    <p>This is a simple example though. It becomes really powerful if your then() callback returns another promise. In that case, the next then() will only be executed once that promise resolves. This pattern can be used for serial HTTP requests, for example (where a request depends on the result of a previous one):</p>
  </blockquote>
  
  <p>This seems to be talking about chains like this:</p>
  
  <pre><code>   asyncFn1(1)
      .then(function(data){return asyncFn2(data)})
      .then(function(data){return asyncFn3(data)})
  </code></pre>
  
  <p>So, if I understand correctly this a). Doesn't apply to me because I don't have a 3rd function. b). Would apply to me if I had three functions because while I run an if statement inside the first $http request, and only inside the if statement do I return another promise. So, theoretically, if I had three async functions to chain, I would need to put my if statement inside a promise? </p>