我有一个用Python写的HTTP可调用云函数,它做一些计算和更新一些Firestore文档。
它实际上是工作在android模拟器和Chrome (Flutter-Web)。
仍然,当我从Chrome (Flutter-Web)触发它时,我得到以下错误:
Instance of '_Future<HttpsCallableResult<dynamic>>'
Error: [firebase_functions/internal] internal
at Object.throw_ [as throw] (http://localhost:54521/dart_sdk.js:5067:11)
at https_callable_web.HttpsCallableWeb.new.call (http://localhost:54521/packages/cloud_functions_web/https_callable_web.dart.lib.js:45:23)
at call.throw (<anonymous>)
at http://localhost:54521/dart_sdk.js:40576:38
at _RootZone.runBinary (http://localhost:54521/dart_sdk.js:40445:59)
at _FutureListener.thenAwait.handleError (http://localhost:54521/dart_sdk.js:35374:33)
at handleError (http://localhost:54521/dart_sdk.js:35947:51)
at Function._propagateToListeners (http://localhost:54521/dart_sdk.js:35973:17)
at _Future.new.[_completeError] (http://localhost:54521/dart_sdk.js:35823:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:54521/dart_sdk.js:35859:31)
at Object._microtaskLoop (http://localhost:54521/dart_sdk.js:40708:13)
at _startMicrotaskLoop (http://localhost:54521/dart_sdk.js:40714:13)
at http://localhost:54521/dart_sdk.js:36191:9
在GCP日志中,我没有显示任何错误。
这是我从CFreturn '{"status":"200", "data": "OK"}'
返回的结果在网络选项卡和状态下的chrome开发人员工具中,我得到一个CORS错误。我确实读了很多SO问题,我确实明白CORS错误显然不是错误的真正原因。
也在同一个选项卡(Network
)下的header ->请求头显示以下Provisional headers are shown
,在Payload
中,{data:null}
和Response
的值没有任何显示,这很奇怪,因为我正在返回"data": "OK"
。
我完全困惑了,因为错误抛出:internal error
没有引导我到任何地方。
我最终通过在云功能上省略region()
来修复它。
我的原始代码:
exports.checkAuth = functions.region("asia-southeast1").https.onCall(async (data, context: functions.https.CallableContext) => {
return `uid: ${context.auth?.uid ?? "X"} - email: ${context.auth?.token.email ?? "X"}`;
});
我把它改成:
exports.checkAuth = functions.https.onCall(async (data, context: functions.https.CallableContext) => {
return `uid: ${context.auth?.uid ?? "X"} - email: ${context.auth?.token.email ?? "X"}`;
});
= = = = = =更新
真正的根本原因是您在云函数和firebase函数中指定的区域不同,例如在我的原始代码中我使用:
functions.region("asia-southeast1").https.onCall()
所以,当我在main.dart
实例化firebase函数时,我必须这样做:
void main() async {
...
final firebaseFunctions = FirebaseFunctions.instanceFor(region: 'asia-southeast1');
...
}