title: Catching promise errors inside another promise's callback
body: <p>The code below runs as expected. If the charge function is invoked, the function fetches the relevant ticket object from <code>firestore</code> and then returns it back to the client.</p>
  
  <p>If the ticket doesn't exist, the function throws a <a href="https://firebase.google.com/docs/reference/functions/functions.https.HttpsError" rel="nofollow noreferrer"><code>HttpsError</code></a> with an error message that will be parsed by the client.</p>
  
  <pre><code>exports.charge = functions.https.onCall(data =&gt; {
    return admin.firestore().collection('tickets').doc(data.ticketId.toString()).get()
      .then((snapshot) =&gt; {
        return { ticket: snapshot.data() }
      })
      .catch((err) =&gt; {
        throw new functions.https.HttpsError(
          'not-found', // code
          'The ticket wasn\'t found in the database'
        );
      });
    });
  </code></pre>
  
  <p>The problem comes after this. I now need to charge the user using Stripe, which is another asynchronous process that will return a <code>Promise</code>. The charge requires the pricing info obtained by the first async method, so this needs to be called after <code>snapshot</code> is retrieved.</p>
  
  <pre><code>exports.charge = functions.https.onCall(data =&gt; {
    return admin.firestore().collection('tickets').doc(data.ticketId.toString()).get()
      .then((snapshot) =&gt; {
        return stripe.charges.create(charge) // have removed this variable as irrelevant for question
          .then(() =&gt; {
            return { success: true };
          })
          .catch(() =&gt; {
            throw new functions.https.HttpsError(
              'aborted', // code
              'The charge failed'
            );
          })
      })
      .catch(() =&gt; {
        throw new functions.https.HttpsError(
          'not-found', // code
          'The ticket wasn\'t found in the database'
        );
      });
    });
  </code></pre>
  
  <p>My problem is with catching errors in the new <code>charge</code> request. It seems that if the charge fails, it successfully calls the first 'aborted' catch, but then it is passed to parent catch, and the error is overridden and the app sees the 'ticket not found' error.</p>
  
  <p>How can I stop this from happening? I need to catch both errors separately and throw a <code>HttpsError</code> for each one.</p>