title: Return promise inside resolve function as its continuation
body: <h3>Context</h3>
  
  <p>I'm working with Angular. I have a <em>service</em> called <em>UserService</em>, that handles login, authentication and user data requests.</p>
  
  <p>The <strong>get</strong> method needs to check if the user has a valid (not expired) token for authentication before making the <code>get</code> request.
  So, if it has, make the request, if not, request a token and <strong>then</strong> make the request.</p>
  
  <h3>Problem</h3>
  
  <p>This <strong>get</strong> method needs to hide its complex requests. It has to return only a Promise as it was making only one request.</p>
  
  <p>So, an example of usage:</p>
  
  <pre><code>UserService
      .get()
      .then(data =&gt; { ... })
      .catch(error =&gt; { ... })
  </code></pre>
  
  <h3>Wrong solution</h3>
  
  <p>Check if the token is expired. If it is, return a request to refresh the token, and there, make and return the get request. If it is not, just make and return the get request. As below:</p>
  
  <pre><code>function get() {
      if (isTokenExpired(token))
          return $http
              .post(url + '/refreshtoken', 'token=' + refreshToken)
              .then(response =&gt; {
                  token = response.data.token
                  return $http.get(url + '?token=' + token)
              })
              .catch(response =&gt; { ... })
      else
          return $http.get(url + '?token=' + token)
  }
  </code></pre>
  
  <p>But it's returning a promise that I will have to handle like this:</p>
  
  <pre><code>UserService
      .get()
      .then(request =&gt; {
          request // THAT IS NOT GOOD
              .then(data =&gt; { ... })
              .catch(error =&gt; { ... })
      })
      .catch(error =&gt; { ... })
  </code></pre>
  
  <p>Anything like the usage example!</p>
  
  <h3>Correct solution</h3>
  
  <p>How to make this <strong>get</strong> method on service, which handles authentication like that and hides everything from the controller that will use, letting it like in the usage example?</p>