Use exit 4 when sending a single recipient message fails due to untrusted identity key

Fixes #88
This commit is contained in:
AsamK 2021-01-16 15:38:38 +01:00
parent e1134d832a
commit 06404667a1
6 changed files with 57 additions and 25 deletions

View file

@ -33,18 +33,26 @@ public class ErrorUtils {
public static List<String> getErrorMessagesFromSendMessageResults(List<SendMessageResult> results) {
List<String> errors = new ArrayList<>();
for (SendMessageResult result : results) {
if (result.isNetworkFailure()) {
errors.add(String.format("Network failure for \"%s\"", result.getAddress().getLegacyIdentifier()));
} else if (result.isUnregisteredFailure()) {
errors.add(String.format("Unregistered user \"%s\"", result.getAddress().getLegacyIdentifier()));
} else if (result.getIdentityFailure() != null) {
errors.add(String.format("Untrusted Identity for \"%s\"", result.getAddress().getLegacyIdentifier()));
String error = getErrorMessageFromSendMessageResult(result);
if (error != null) {
errors.add(error);
}
}
return errors;
}
public static String getErrorMessageFromSendMessageResult(SendMessageResult result) {
if (result.isNetworkFailure()) {
return String.format("Network failure for \"%s\"", result.getAddress().getLegacyIdentifier());
} else if (result.isUnregisteredFailure()) {
return String.format("Unregistered user \"%s\"", result.getAddress().getLegacyIdentifier());
} else if (result.getIdentityFailure() != null) {
return String.format("Untrusted Identity for \"%s\"", result.getAddress().getLegacyIdentifier());
}
return null;
}
private static int handleSendMessageResultErrors(List<String> errors) {
if (errors.size() == 0) {
return 0;