]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/ReceiveCommand.java
Extend logging
[signal-cli] / src / main / java / org / asamk / signal / commands / ReceiveCommand.java
index 79d0ee1dad5dad95058c98fa1820ce66d434bec4..16421b62ca3139c48244149fc6082548d0cfe070 100644 (file)
@@ -10,8 +10,10 @@ import org.asamk.signal.OutputType;
 import org.asamk.signal.ReceiveMessageHandler;
 import org.asamk.signal.commands.exceptions.CommandException;
 import org.asamk.signal.commands.exceptions.IOErrorException;
+import org.asamk.signal.commands.exceptions.UserErrorException;
 import org.asamk.signal.json.JsonReceiveMessageHandler;
 import org.asamk.signal.manager.Manager;
+import org.asamk.signal.manager.api.AlreadyReceivingException;
 import org.asamk.signal.manager.api.ReceiveConfig;
 import org.asamk.signal.output.JsonWriter;
 import org.asamk.signal.output.OutputWriter;
@@ -79,6 +81,8 @@ public class ReceiveCommand implements LocalCommand, JsonRpcSingleCommand<Receiv
             m.receiveMessages(Optional.ofNullable(duration), Optional.ofNullable(maxMessages), handler);
         } catch (IOException e) {
             throw new IOErrorException("Error while receiving messages: " + e.getMessage(), e);
+        } catch (AlreadyReceivingException e) {
+            throw new UserErrorException("Receive command cannot be used if messages are already being received.", e);
         }
     }
 
@@ -103,8 +107,10 @@ public class ReceiveCommand implements LocalCommand, JsonRpcSingleCommand<Receiv
             jsonWriter.write(messages);
         } catch (IOException e) {
             throw new IOErrorException("Error while receiving messages: " + e.getMessage(), e);
+        } catch (AlreadyReceivingException e) {
+            throw new UserErrorException("Receive command cannot be used if messages are already being received.", e);
         }
     }
 
-    record ReceiveParams(Double timeout, Integer maxMessages) {}
+    public record ReceiveParams(Double timeout, Integer maxMessages) {}
 }