title: How to handle errors in client side (Android) from cloud functions (functions.https.HttpsError) using Typescript
body: <p>First I'm use Typescript to write cloud functions to create an account with Firebase authentication. After creating new account, tried to add custom claims to the account and add the user info to the Firebase real-time database these steps complete successfully.</p>
  
  <p>The problem appears when adding already existing account. The error prints in functions log but I cant throw it to Android</p>
  
  <p><a href="https://i.stack.imgur.com/EqlAs.jpg" rel="nofollow noreferrer">My firebase cloud functions log</a></p>
  
  <p>cloud functions code:.</p>
  
  <pre><code>import * as functions from 'firebase-functions';
  import * as admin from 'firebase-admin';
  import { User } from './model/User';
  
  admin.initializeApp();
  
  const db = admin.database();
  
  exports.createSellerAccount = functions.https.onCall((data, context) =&gt; {
    const userEmail = data.email;
    const userPassword = data.password;
    const user: User = new User();
    const newUserData = JSON.parse(data.newUser);
  
    user.setFirstName(newUserData.firstName);
    user.setLastName(newUserData.lastName);
    user.setMobileNumber(newUserData.mobileNumber);
  
    admin.auth().createUser({
      email: userEmail,
      password: userPassword
    }).then(function (userRecord) {
      // See the UserRecord reference doc for the contents of userRecord.
      const additionalClaims = {
        sellerAccount: true
      };
  
      admin.auth().setCustomUserClaims(userRecord.uid, additionalClaims)
        .then(function (customToken) {
          // Send token back to client
          console.log("Successfully token created new user:", userRecord.uid);
        })
        .catch((error) =&gt; {
          console.log("Error creating custom token:", error);
        });
  
      db.ref("Users/" + userRecord.uid).set(user)
        .then(() =&gt; {
          console.log("seller info inserted successfully");
        })
        .catch(function (error) {
          console.log("Error while inserting seller info:", error);
        });
  
    }).catch(function(error) {
      // console.log("Error creating new user:", error);
      throw new functions.https.HttpsError('already-exists',error);
    });
  
  })
  </code></pre>
  
  <p>Android code:.</p>
  
  <pre><code>private void createAccount() {
      ekhtarSeller.showProgressDialog(this);
      newUser.setFirstName(tietFirstName.getText().toString().trim());
      newUser.setLastName(tietLastName.getText().toString().trim());
      newUser.setMobileNumber(tietMobileNumber.getText().toString().trim());
  
      HashMap&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();
      data.put("email", tietEmail.getText().toString().trim());
      data.put("password", tietPassword.getText().toString().trim());
      data.put("newUser", new Gson().toJson(newUser));
  
      mFunctions
              .getHttpsCallable("createSellerAccount")
              .call(data)
              .continueWith(new Continuation&lt;HttpsCallableResult, String&gt;() {
                  @Override
                  public String then(@NonNull Task&lt;HttpsCallableResult&gt; task) throws Exception {
                      // This continuation runs on either success or failure, but if the task
                      // has failed then getResult() will throw an Exception which will be
                      // propagated down.
                      ekhtarSeller.getProgressDialog().cancel();
                      String result = (String) task.getResult().getData();
                      Toast.makeText(CreateAccountActivity.this, result, Toast.LENGTH_SHORT).show();
                      return result;
                  }
              });
  }
  </code></pre>