是否可以从HTTPs的可调用函数抛出Auth Error?
我的意思是,而不是这个
if (err.code === "auth/email-already-exists") {
throw new functions.https.HttpsError(
"invalid-argument",
"The email address is already in use by other account"
);
}
类似的东西
exports.signUp = functions
.region("us-central1")
.runWith({ memory: "2GB", timeoutSeconds: 120 })
.https.onCall(async (data, context) => {
...
if (err.code === "auth/email-already-exists") {
throw err;
}
...
}
可调用函数应返回HttpsError
的一个实例,该实例需要gRPC错误代码,以便将错误的详细信息正确传输给调用客户端。如果抛出不同的错误类型,客户端将只看到带有代码和消息"internal"
的HttpsError
——为了安全起见,不会向客户端发送任何细节。
如果要传递Firebase错误的错误代码,可以使用第三个参数。也可以考虑使用"failed-precondition"
(首选(或"already-exists"
(如果是资源(。
if (err.code === "auth/email-already-exists") {
throw new functions.https.HttpsError(
"invalid-argument",
"The email address is already in use by other account",
{ code: err.code }
);
}