From 91e7185fe97c888f339f5775174047899e051e52 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 15 Oct 2018 17:11:13 +0300 Subject: notifications: handle FCM errors --- .../java/com/juick/components/FirebaseManager.java | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'juick-notifications/src/main/java/com/juick/components') diff --git a/juick-notifications/src/main/java/com/juick/components/FirebaseManager.java b/juick-notifications/src/main/java/com/juick/components/FirebaseManager.java index 6bab725a..f88f3201 100644 --- a/juick-notifications/src/main/java/com/juick/components/FirebaseManager.java +++ b/juick-notifications/src/main/java/com/juick/components/FirebaseManager.java @@ -9,6 +9,7 @@ import com.google.auth.oauth2.GoogleCredentials; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; import com.google.firebase.messaging.FirebaseMessaging; +import com.google.firebase.messaging.FirebaseMessagingException; import com.google.firebase.messaging.Message; import com.juick.ExternalToken; import com.juick.User; @@ -73,21 +74,20 @@ public class FirebaseManager implements NotificationListener { ApiFutures.addCallback(response, new ApiFutureCallback() { @Override public void onFailure(Throwable t) { - logger.warn("Firebase exception", t); - /* - List results = result.getResults(); - for (int i = 0; i < results.size(); i++) { - Result currentResult = results.get(i); - logger.info("RES {}: {}", i, currentResult); - List errorCodes = Arrays.asList(Constants.ERROR_MISMATCH_SENDER_ID, Constants.ERROR_NOT_REGISTERED); - if (errorCodes.contains(currentResult.getErrorCodeName())) { - // assuming results are in order of regids - // http://stackoverflow.com/a/11594531/1097384 - String currentId = regids.get(i); - logger.info("{} is scheduled to remove", currentId); - notificationsManager.addInvalidGCMToken(currentId); + if (t instanceof FirebaseMessagingException) { + FirebaseMessagingException e = (FirebaseMessagingException) t; + if (e.getErrorCode().equals("messaging/invalid-argument") + || e.getErrorCode().equals("messaging/registration-token-not-registered") + || e.getErrorCode().equals("messaging/invalid-registration-token")) { + // invalid token + logger.info("{} is scheduled to remove", token); + notificationsManager.addInvalidGCMToken(token); + } else { + logger.warn("Unhandled FirebaseMessaging exception", t); } - }*/ + } else { + logger.warn("Unhandled FCM exception", t); + } } @Override -- cgit v1.2.3