]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/Main.java
Use pattern matching switch cases
[signal-cli] / src / main / java / org / asamk / signal / Main.java
index 429cdc939199ae59403e12bd1da65fb9b2ef44bb..00d9d7a9fbe2944becb05037d7922b81d96a2494 100644 (file)
@@ -24,6 +24,7 @@ import net.sourceforge.argparse4j.inf.Namespace;
 
 import org.asamk.signal.commands.exceptions.CommandException;
 import org.asamk.signal.commands.exceptions.IOErrorException;
+import org.asamk.signal.commands.exceptions.RateLimitErrorException;
 import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
 import org.asamk.signal.commands.exceptions.UntrustedKeyErrorException;
 import org.asamk.signal.commands.exceptions.UserErrorException;
@@ -108,16 +109,13 @@ public class Main {
     }
 
     private static int getStatusForError(final CommandException e) {
-        if (e instanceof UserErrorException) {
-            return 1;
-        } else if (e instanceof UnexpectedErrorException) {
-            return 2;
-        } else if (e instanceof IOErrorException) {
-            return 3;
-        } else if (e instanceof UntrustedKeyErrorException) {
-            return 4;
-        } else {
-            return 2;
-        }
+        return switch (e) {
+            case UserErrorException userErrorException -> 1;
+            case UnexpectedErrorException unexpectedErrorException -> 2;
+            case IOErrorException ioErrorException -> 3;
+            case UntrustedKeyErrorException untrustedKeyErrorException -> 4;
+            case RateLimitErrorException rateLimitErrorException -> 5;
+            case null, default -> 2;
+        };
     }
 }