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:
{"error":{"status":"INTERNAL","message":"INTERNAL"}}
In the Firebase console I also get this:
Unhandled error Error: Unknown error status: auth/invalid-email
Which doesn't make much sense since I am actually handling the error. This is the code of the cloud function:
exports.createUser = (data, context) => {
return admin.auth().createUser({
email: data.email,
password: data.password
}).catch((error) => {
throw new functions.https.HttpsError(error.errorInfo.code, error.errorInfo.message);
});
}
As shown I've tried to use throw functions.https.HttpsError
which is what the documentation suggests.
I've also tried return functions.https.HttpsError
or even throwing my own error with the same result.
I've used try/catch with await
instead of using then()
and catch()
. Same result. The functions console still informs me that the error is not handled which is absurd.
So how can I throw a proper error to my users when using a callable cloud function?
exports.createUser = functions.https.onCall()
– Doug Stevensonexports.createUser = functions.https.onCall(createUser);
. It works for creating users. – Pier