Firebase Cloud Functions - 抛出 Auth 错误
Firebase Cloud Functions - Throw Auth Error
是否可以从 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;
}
...
}
Callable Functions 应该 return HttpsError
which requires gRPC error codes 的一个实例,以便将错误的详细信息正确传输给调用客户端。如果您抛出不同的错误类型,客户端将只会看到带有代码和消息 "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 }
);
}
是否可以从 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;
}
...
}
Callable Functions 应该 return HttpsError
which requires gRPC error codes 的一个实例,以便将错误的详细信息正确传输给调用客户端。如果您抛出不同的错误类型,客户端将只会看到带有代码和消息 "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 }
);
}