可以从HTTPs调用函数抛出Auth错误吗?
我是说,而不是这个
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;
}
...
}发布于 2021-11-25 16:28:21
可调用函数应该返回一个HttpsError实例,该实例需要gRPC错误码,因此错误的详细信息将正确地传递给调用客户端。如果您抛出不同的错误类型,客户端将只看到带有代码和消息"internal"的"internal"--为了安全起见,不会向客户端发送详细信息。
如果要传递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 }
);
}https://stackoverflow.com/questions/70114313
复制相似问题