是否可以從 HTTPs 可呼叫函式中拋出身份驗證錯誤?
我的意思是,而不是這個
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;
}
...
}
uj5u.com熱心網友回復:
可呼叫函式應回傳一個HttpsError需要gRPC 錯誤代碼的實體,以便將錯誤的詳細資訊正確傳輸到呼叫客戶端。如果你拋出一個不同的錯誤型別,客戶端只會看到一個HttpsError帶有代碼和訊息的"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://www.uj5u.com/shujuku/365987.html
