aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java')
-rw-r--r--app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java41
1 files changed, 35 insertions, 6 deletions
diff --git a/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java b/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java
index a32e77a4..199b1fbd 100644
--- a/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java
+++ b/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java
@@ -5,9 +5,15 @@
package com.wireguard.android.util;
+import android.content.res.Resources;
import android.support.annotation.Nullable;
import android.util.Log;
+import com.wireguard.android.Application;
+import com.wireguard.android.R;
+import com.wireguard.config.ParseException;
+import com.wireguard.crypto.Key;
+
import java9.util.concurrent.CompletionException;
import java9.util.function.BiConsumer;
@@ -34,12 +40,35 @@ public enum ExceptionLoggers implements BiConsumer<Object, Throwable> {
return throwable;
}
- public static String unwrapMessage(Throwable throwable) {
- throwable = unwrap(throwable);
- final String message = throwable.getMessage();
- if (message != null)
- return message;
- return throwable.getClass().getSimpleName();
+ public static String unwrapMessage(final Throwable throwable) {
+ final Throwable innerThrowable = unwrap(throwable);
+ final Resources resources = Application.get().getResources();
+ String message;
+ if (innerThrowable instanceof ParseException) {
+ final ParseException parseException = (ParseException) innerThrowable;
+ message = resources.getString(R.string.parse_error, parseException.getText(), parseException.getContext());
+ if (parseException.getMessage() != null)
+ message += ": " + parseException.getMessage();
+ } else if (innerThrowable instanceof Key.KeyFormatException) {
+ final Key.KeyFormatException keyFormatException = (Key.KeyFormatException) innerThrowable;
+ switch (keyFormatException.getFormat()) {
+ case BASE64:
+ message = resources.getString(R.string.key_length_base64_exception_message);
+ break;
+ case BINARY:
+ message = resources.getString(R.string.key_length_exception_message);
+ break;
+ case HEX:
+ message = resources.getString(R.string.key_length_hex_exception_message);
+ break;
+ default:
+ // Will never happen, as getFormat is not nullable.
+ message = null;
+ }
+ } else {
+ message = throwable.getMessage();
+ }
+ return message != null ? message : innerThrowable.getClass().getSimpleName();
}
@Override