android - 从 android 应用程序调用异步 Firebase 函数时出现“内部”异常
问题描述
我正在尝试从 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};
});
});
例外:
com.google.firebase.functions.FirebaseFunctionsException: INTERNAL
解决方案
处理可调用函数中的错误的文档表明必须返回functions.https.HttpsError的实例:
为确保客户端获得有用的错误详细信息,请通过抛出(或返回 Promise 被拒绝)的实例从可调用返回错误
functions.https.HttpsError
...HttpsError
INTERNAL 和内部代码。
您的调用似乎calc.calculate()
返回了一个未正确处理的错误,从而导致返回的错误状态为 INTERNAL。
按照上面链接的文档中的示例,您的代码应类似于:
if(err) {
// handle error
throw new functions.https.HttpsError('calc-error', 'some error message');
} else {
const data = response.dataValue;
}
推荐阅读
- sql-server - SSAS 处理不断跳过记录
- nhibernate - NHibernate 无法解析从子目录加载的动态加载程序集中的类
- jquery - jquery替换括号之间的文本
- java - 如何尽可能兼容地测试多个断言?
- r - 具有经验密度和 dnorm 函数的叠加直方图
- r - 使用 R 中的 apply 函数未正确计算中位数
- c# - 如何以多种语言显示版本 DisplayName
- python - 如何使用 TensorFlow 在 Returnn 中加载经过训练的网络的权重
- cmake - 使用 CPack 打包时是否需要 CMake 安装步骤?
- github - 从 SVN 连接到 GitHub 时出错