refactor: `ShardNotOwnedException` should be send over `Mono.send()`
authorKai Moritz <kai@juplo.de>
Tue, 29 Aug 2023 17:36:15 +0000 (19:36 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 27 Jan 2024 15:38:56 +0000 (16:38 +0100)
src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHome.java
src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/ChatRoomChannel.java

index 4fa4d9b..ac7a980 100644 (file)
@@ -44,9 +44,9 @@ public class ShardedChatHome implements ChatHome
   public Mono<ChatRoom> getChatRoom(UUID id)
   {
     int shard = selectShard(id);
-    if (chatHomes[shard] == null)
-      throw new ShardNotOwnedException(shard);
-    return chatHomes[shard].getChatRoom(id);
+    return chatHomes[shard] == null
+        ? Mono.error(new ShardNotOwnedException(shard))
+        : chatHomes[shard].getChatRoom(id);
   }
 
   @Override
index f6f50cc..234554e 100644 (file)
@@ -369,12 +369,12 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener
   {
     if (loadInProgress)
     {
-      throw new LoadInProgressException();
+      return Mono.error(new LoadInProgressException());
     }
 
     if (!isShardOwned[shard])
     {
-      throw new ShardNotOwnedException(shard);
+      return Mono.error(new ShardNotOwnedException(shard));
     }
 
     return Mono.justOrEmpty(chatrooms[shard].get(id));