Я получаю ошибку как INTERNAL
при вызове облачной функции Firebase из моего приложения.
Код сервера:
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, переданного в функцию.
Как получить доступ к свойствам переданных свойств объекта?