firebase - 使用 Java SDK : how to handle correctly and differentiate failures 进行 FCM 消息传递

标签 firebase firebase-admin

我正在将 Firebase Cloud Messaging 与 Java SDK (com.google.firebase:firebase-admin v 5.9.0) 结合使用。

处理 Java 代码中的错误的唯一方法是捕获 ExecutionException:

Message message = buildMessage(token,payload);
try {
    String response = FirebaseMessaging.getInstance().sendAsync(message).get();
} catch (ExecutionException e) {
    LOGGER.error("ExecutionException Error pushing notif : ", e);
}
// Response is a message ID string.
LOGGER.info("Successfully sent message: " + response);

如果我想检测已删除的 token ,我必须读取 ExecutionException(FireBaseMessagingException)中包装的异常,并测试该消息是否为“未找到请求的实体”:

if(e.getCause().getMessage().equals("Requested entity was not found.") {
// token is deleted 
}

如果我想检测网络故障,我必须读取 ExecutionException(FireBaseMessagingException)中包装的异常,并测试该消息是否为“调用 FCM 后端服务时出错”:

if(e.getCause().getMessage().equals("Error while calling FCM backend service") {
// network problem, I have to retry 
}

要采取的操作取决于此检测,这是非常脆弱的。是否可以实现更准确的错误判断?

最佳答案

关于firebase - 使用 Java SDK : how to handle correctly and differentiate failures 进行 FCM 消息传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49925954/

相关文章:

java - Firebase Admin SDK @Exclude 注释不起作用

python - 导入错误 : No module named google. 身份验证

firebase - 根据动态用户属性创建受众

typescript - 是否可以使用节点 js 云功能访问 FieldValue?

node.js - 后端的 Firebase 管理员用于 verifyIdToken 并使用 Firestore

javascript - `Firebase` 包被成功找到。但是,这个包本身指定了一个无法解析的 `main` 模块字段

node.js - 火力地堡存储 : list files in a specific directory

javascript - 创建用户,保存数据,然后更改页面

javascript - 如何在 JavaScript 中将 JSON 键保留为字符串

firebase - 在 Firestore 中存储标签的最有效方法是什么?