refactor: Moved succes/error-logging to outer stream-definitions
authorKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 07:23:13 +0000 (08:23 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 07:32:37 +0000 (08:32 +0100)
src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java

index 6108163..6b290fd 100644 (file)
@@ -19,17 +19,18 @@ public interface StorageStrategy
     return writeChatRoomInfo(
         chatHomeService
             .getChatRoomInfo()
-            .doOnComplete(() -> log.info("Stored {}", chatHomeService))
-            .doOnError(throwable -> log.error("Could not store {}: {}", chatHomeService, throwable))
             .doOnNext(chatRoomInfo ->
                 writeChatRoomData(
                     chatRoomInfo.getId(),
                     chatHomeService
                         .getChatRoomData(chatRoomInfo.getId())
                         .flatMapMany(chatRoomData -> chatRoomData.getMessages())
-                        .doOnComplete(() -> log.info("Stored {}", chatRoomInfo))
-                        .doOnError(throwable -> log.error("Could not store {}: {}", chatRoomInfo, throwable)))
-                    .subscribe()));
+                        )
+                    .doOnComplete(() -> log.info("Stored {}", chatRoomInfo))
+                    .doOnError(throwable -> log.error("Could not store {}: {}", chatRoomInfo, throwable))
+                    .subscribe()))
+        .doOnComplete(() -> log.info("Stored {}", chatHomeService))
+        .doOnError(throwable -> log.error("Could not store {}: {}", chatHomeService, throwable));
   }
 
   Flux<ChatRoomInfo> writeChatRoomInfo(Flux<ChatRoomInfo> chatRoomInfoFlux);