Эх сурвалжийг харах

create constants for custom exceptions

David Luhmer 6 жил өмнө
parent
commit
8133875769

+ 6 - 3
src/main/java/com/nextcloud/android/sso/InputStreamBinder.java

@@ -61,6 +61,9 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
+import static com.nextcloud.android.sso.aidl.NextcloudRequest.EXCEPTION_ACCOUNT_NOT_FOUND;
+import static com.nextcloud.android.sso.aidl.NextcloudRequest.EXCEPTION_INVALID_TOKEN;
+
 
 /**
  * Stream binder to pass usable InputStreams across the process boundary in Android.
@@ -145,12 +148,12 @@ public class InputStreamBinder extends IInputStreamService.Stub {
     private InputStream processRequest(final NextcloudRequest request) throws UnsupportedOperationException, com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException {
         Account account = AccountUtils.getOwnCloudAccountByName(context, request.accountName); // TODO handle case that account is not found!
         if(account == null) {
-            throw new IllegalStateException("CE_2"); // Custom Exception 2 (Account not found)
+            throw new IllegalStateException(EXCEPTION_ACCOUNT_NOT_FOUND);
         }
 
-        // Validate token & package name
+        // Validate token
         if (!isValid(request)) {
-            throw new IllegalStateException("CE_1"); // Custom Exception 1 (Invalid token or package name)
+            throw new IllegalStateException(EXCEPTION_INVALID_TOKEN);
         }
 
         // Validate URL

+ 2 - 0
src/main/java/com/nextcloud/android/sso/aidl/NextcloudRequest.java

@@ -27,6 +27,8 @@ import java.util.Map;
 public class NextcloudRequest implements Serializable {
 
     private static final long serialVersionUID = 215521212534236L; //assign a long value
+    public static final String EXCEPTION_INVALID_TOKEN = "CE_1";
+    public static final String EXCEPTION_ACCOUNT_NOT_FOUND = "CE_2";
 
     public String method;
     public Map<String, List<String>> header = new HashMap<>();