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,12 +98,17 @@ 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();
if (firebaseMessagingException.getMessagingErrorCode() == MessagingErrorCode.QUOTA_EXCEEDED) {
logger.info("FCM request failed with quota exceeded; retry-after: {}, response body: {}",
firebaseMessagingException.getHttpResponse().getHeaders().get("retry-after"),
firebaseMessagingException.getHttpResponse().getContent());
}
} else if (firebaseMessagingException.getHttpResponse() != null) { } else if (firebaseMessagingException.getHttpResponse() != null) {
errorCode = "http" + firebaseMessagingException.getHttpResponse().getStatusCode(); errorCode = "http" + firebaseMessagingException.getHttpResponse().getStatusCode();
} else { } else {
@ -115,9 +120,7 @@ public class FcmSender implements PushNotificationSender {
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);
}
});
} }
} }