【发布时间】:2019-09-03 21:06:04
【问题描述】:
当我从我的应用调用 Firebase 云函数时,我收到了 INTERNAL 的错误。
服务器代码:
exports.addToCart = functions.https.onCall((data, context) => {
// Checking that the user is authenticated.
if (!context.auth) {
// Throwing an HttpsError so that the client gets the error details.
throw new functions.https.HttpsError(
"failed-precondition",
"The function must be called " + "while authenticated."
);
}
// Get data
const food = data.food;
// Get user details
const uid = context.auth.uid;
console.log("User id " + uid);
console.log("Food name " + food.name);
return "Added to cart successfully."
});
Java 代码:
addToCartTask(foodItem)
.addOnSuccessListener(s -> {
Log.e(TAG, "Success : " + s);
})
.addOnFailureListener(e -> {
Log.e(TAG, "Error : " + e.getLocalizedMessage());
});
private Task<String> addToCartTask(Food foodItem) {
// Create the arguments to the callable function.
Map<String, Object> objectHashMap = new HashMap<>();
objectHashMap.put("foodItem", foodItem);
Gson gson = new Gson();
String data = gson.toJson(objectHashMap);
return firebaseFunctions
.getHttpsCallable("addToCart")
.call(data);
}
错误响应是由于访问了函数中传递的自定义 java 对象的属性。
如何访问传递的对象属性的属性?
【问题讨论】:
标签: android firebase google-cloud-functions