log notification send fail reason in db for easier debugging

This commit is contained in:
2026-01-14 15:34:29 +01:00
parent 41f04620ba
commit ddbf925caf
2 changed files with 4 additions and 2 deletions
@@ -50,6 +50,9 @@ public class Notification {
@Column(nullable = false)
private int failedSendAttempts = 0;
@Column
private String lastFailureReason;
@Column(nullable = false)
private LocalDateTime createdAt;
@@ -21,7 +21,6 @@ import java.util.logging.Logger;
@Service
public class NotificationSender {
private final NotificationTokenRepository notificationTokenRepository;
private final FirebaseMessageBuilder firebaseMessageBuilder;
private final Logger logger = Logger.getLogger(NotificationSender.class.getName());
private final FirebaseMessaging firebaseMessaging;
@@ -34,7 +33,6 @@ public class NotificationSender {
@Autowired(required = false) FirebaseMessaging firebaseMessaging,
NotificationRepository notificationRepository, NotificationProperties notificationProperties
) {
this.notificationTokenRepository = notificationTokenRepository;
this.firebaseMessageBuilder = firebaseMessageBuilder;
this.firebaseMessaging = firebaseMessaging;
this.notificationRepository = notificationRepository;
@@ -76,6 +74,7 @@ public class NotificationSender {
@Override
public void onFailure(Throwable t) {
notification.incrementFailedSendAttempts();
notification.setLastFailureReason(t.getMessage());
if (notification.getFailedSendAttempts() >= notificationProperties.getMaxFailedSendAttempts()) {
notification.setStatus(NotificationStatus.FAILED);
}