gpt4 book ai didi

android - 从 android 应用程序调用异步 Firebase 函数时出现 “INTERNAL” 异常

转载 作者:行者123 更新时间:2023-12-01 11:16:26 26 4
gpt4 key购买 nike

我正在尝试从 android 应用程序调用异步 Firebase 函数,并在函数返回时出现“INTERNAL”异常。

安卓:

 private Task<String> fetchData() {
// Create the arguments to the callable function, which is just one string
Map<String, Object> data = new HashMap<>();
data.put(“id”, “abc”);

return FirebaseFunctions.getInstance()
.getHttpsCallable(“calculate”)
.call(data)
.continueWith(new Continuation<HttpsCallableResult, String>() {
@Override
public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
Map<String, Object> result = (Map<String, Object>) task.getResult().getData();
return (String)result.get(“data”);
}
});
}

火力基地功能:
exports.calculate = functions.https.onCall((data, context) => {
const text = data.id;
return calc.calculate( (err, response) => {
if(err) {
// handle error
} else {
const data = response.dataValue;
}
}).then(() => {
return {“data”: data};
});
});

异常(exception):
com.google.firebase.functions.FirebaseFunctionsException: INTERNAL

最佳答案

handling errors in callable functions 的文档表示 functions.https.HttpsError 的实例必须退回:

To ensure the client gets useful error details, return errors from a callable by throwing (or returning a Promise rejected with) an instance of functions.https.HttpsError... If an error other than HttpsError is thrown from your functions, your client instead receives an error with the message INTERNAL and the code internal.



您的 calc.calculate() 似乎很可能call 正在返回未正确处理的错误,导致返回的错误状态为 INTERNAL。

按照上面链接的文档中的示例,您的代码应类似于:
if(err) {
// handle error
throw new functions.https.HttpsError('calc-error', 'some error message');
} else {
const data = response.dataValue;
}

关于android - 从 android 应用程序调用异步 Firebase 函数时出现 “INTERNAL” 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50429595/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com