title: How to throw an error on a Firebase callable cloud function?
body: <p>I'm trying to create a new user on Firebase using a callable cloud function. Whenever there is an error (eg: the email is invalid) the function always returns the same cryptic error to my Firebase app no matter what I do:</p>
  
  <pre><code>{"error":{"status":"INTERNAL","message":"INTERNAL"}}
  </code></pre>
  
  <p>In the Firebase console I also get this:</p>
  
  <pre><code>Unhandled error Error: Unknown error status: auth/invalid-email
  </code></pre>
  
  <p>Which doesn't make much sense since I am actually handling the error. This is the code of the cloud function:</p>
  
  <pre><code>exports.createUser = (data, context) =&gt; {
      return admin.auth().createUser({
          email: data.email,
          password: data.password
      }).catch((error) =&gt; {
          throw new functions.https.HttpsError(error.errorInfo.code, error.errorInfo.message);
      });
  }
  </code></pre>
  
  <p>As shown I've tried to use <code>throw functions.https.HttpsError</code> which is what the <a href="https://firebase.google.com/docs/functions/callable#handle_errors" rel="noreferrer">documentation suggests</a>.</p>
  
  <p>I've also tried <code>return functions.https.HttpsError</code> or even throwing my own error with the same result. </p>
  
  <p>I've used try/catch with <code>await</code> instead of using <code>then()</code> and <code>catch()</code>. Same result. The functions console still informs me that the error is not handled which is absurd.</p>
  
  <p>So how can I throw a proper error to my users when using a callable cloud function?</p>