Handle send failures as non fatal and return detailed results in json output

Fixes #348
This commit is contained in:
AsamK 2021-12-11 12:44:11 +01:00
parent ceafe96e81
commit 06e93b84da
13 changed files with 191 additions and 138 deletions

View file

@ -11,14 +11,12 @@ import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.manager.groups.GroupSendingNotAllowedException;
import org.asamk.signal.manager.groups.NotAGroupMemberException;
import org.asamk.signal.output.JsonWriter;
import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.output.PlainTextWriter;
import org.asamk.signal.util.CommandUtil;
import org.asamk.signal.util.ErrorUtils;
import java.io.IOException;
import java.util.Map;
import static org.asamk.signal.util.SendMessageResultUtils.outputResult;
public class SendReactionCommand implements JsonRpcLocalCommand {
@ -72,8 +70,7 @@ public class SendReactionCommand implements JsonRpcLocalCommand {
CommandUtil.getSingleRecipientIdentifier(targetAuthor, m.getSelfNumber()),
targetTimestamp,
recipientIdentifiers);
outputResult(outputWriter, results.timestamp());
ErrorUtils.handleSendMessageResults(results.results());
outputResult(outputWriter, results);
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new UserErrorException(e.getMessage());
} catch (IOException e) {
@ -81,13 +78,4 @@ public class SendReactionCommand implements JsonRpcLocalCommand {
.getSimpleName() + ")", e);
}
}
private void outputResult(final OutputWriter outputWriter, final long timestamp) {
if (outputWriter instanceof PlainTextWriter writer) {
writer.println("{}", timestamp);
} else {
final var writer = (JsonWriter) outputWriter;
writer.write(Map.of("timestamp", timestamp));
}
}
}