Add logs to FCM quota failures

This commit is contained in:
Ravi Khadiwala 2025-02-07 13:11:51 -06:00 committed by ravi-signal
parent 5d062285c2
commit a9975e524b
1 changed files with 21 additions and 18 deletions

View File

@ -98,26 +98,29 @@ public class FcmSender implements PushNotificationSender {
return GoogleApiUtil.toCompletableFuture(firebaseMessagingClient.sendAsync(builder.build()), executor) return GoogleApiUtil.toCompletableFuture(firebaseMessagingClient.sendAsync(builder.build()), executor)
.whenComplete((ignored, throwable) -> sample.stop(SEND_NOTIFICATION_TIMER)) .whenComplete((ignored, throwable) -> sample.stop(SEND_NOTIFICATION_TIMER))
.thenApply(ignored -> new SendPushNotificationResult(true, Optional.empty(), false, Optional.empty())) .thenApply(ignored -> new SendPushNotificationResult(true, Optional.empty(), false, Optional.empty()))
.exceptionally(throwable -> { .exceptionally(ExceptionUtils.exceptionallyHandler(FirebaseMessagingException.class,
if (ExceptionUtils.unwrap(throwable) instanceof final FirebaseMessagingException firebaseMessagingException) { firebaseMessagingException -> {
final String errorCode; final String errorCode;
if (firebaseMessagingException.getMessagingErrorCode() != null) { if (firebaseMessagingException.getMessagingErrorCode() != null) {
errorCode = firebaseMessagingException.getMessagingErrorCode().name(); errorCode = firebaseMessagingException.getMessagingErrorCode().name();
} else if (firebaseMessagingException.getHttpResponse() != null) { if (firebaseMessagingException.getMessagingErrorCode() == MessagingErrorCode.QUOTA_EXCEEDED) {
errorCode = "http" + firebaseMessagingException.getHttpResponse().getStatusCode(); logger.info("FCM request failed with quota exceeded; retry-after: {}, response body: {}",
} else { firebaseMessagingException.getHttpResponse().getHeaders().get("retry-after"),
logger.warn("Received an FCM exception with no error code", firebaseMessagingException); firebaseMessagingException.getHttpResponse().getContent());
errorCode = "unknown"; }
} } else if (firebaseMessagingException.getHttpResponse() != null) {
errorCode = "http" + firebaseMessagingException.getHttpResponse().getStatusCode();
} else {
logger.warn("Received an FCM exception with no error code", firebaseMessagingException);
errorCode = "unknown";
}
final boolean unregistered = final boolean unregistered =
firebaseMessagingException.getMessagingErrorCode() == MessagingErrorCode.UNREGISTERED; firebaseMessagingException.getMessagingErrorCode() == MessagingErrorCode.UNREGISTERED;
return new SendPushNotificationResult(false, Optional.of(errorCode), unregistered, Optional.empty()); return new SendPushNotificationResult(false, Optional.of(errorCode), unregistered, Optional.empty());
} else { }));
throw ExceptionUtils.wrap(throwable);
}
});
} }
} }