Improve behavior with synchronous and asynchronous receivers

This commit is contained in:
AsamK 2022-11-01 13:56:40 +01:00
parent eec3d782d3
commit 9096229637
4 changed files with 56 additions and 29 deletions

View 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,6 +107,8 @@ 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);
}
}