I'm using Firebase Cloud Messaging with Java SDK (com.google.firebase:firebase-admin v 5.9.0).
The only way to treat errors in Java code is to catch an 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);
If I want to detect a deleted Token, I have to read the wrapped exception in ExecutionException (a FireBaseMessagingException), and test that message is "Requested entity was not found":
if(e.getCause().getMessage().equals("Requested entity was not found.") {
// token is deleted
}
If I want to detect a network failure, I have to read the wrapped exception in ExecutionException (a FireBaseMessagingException), and test that message is "Error while calling FCM backend service":
if(e.getCause().getMessage().equals("Error while calling FCM backend service") {
// network problem, I have to retry
}
Actions to make depend on this detection, which is very fragile. Is it possible to implement a more accurate determination of errors?