diff options
author | 2018-10-15 17:11:13 +0300 | |
---|---|---|
committer | 2018-10-15 17:11:13 +0300 | |
commit | 91e7185fe97c888f339f5775174047899e051e52 (patch) | |
tree | 06772b303839aa14bd6b9eda49c9eb47ee7bb2f5 /juick-notifications/src/main/java | |
parent | dd0a790d2431c6022b255ea5d02ab8d995ec6a45 (diff) |
notifications: handle FCM errors
Diffstat (limited to 'juick-notifications/src/main/java')
-rw-r--r-- | juick-notifications/src/main/java/com/juick/components/FirebaseManager.java | 28 |
1 files changed, 14 insertions, 14 deletions
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<String>() { @Override public void onFailure(Throwable t) { - logger.warn("Firebase exception", t); - /* - List<Result> results = result.getResults(); - for (int i = 0; i < results.size(); i++) { - Result currentResult = results.get(i); - logger.info("RES {}: {}", i, currentResult); - List<String> 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 |