android/source/res/values/strings.xml                                          
|    4 +
 android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java     
|    8 +-
 android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java 
|   27 +++++++++-
 3 files changed, 34 insertions(+), 5 deletions(-)

New commits:
commit 78ecdbc2f69b9d812cf879f662e7c1277d3c9b07
Author: Jacobo Aragunde Pérez <jaragu...@igalia.com>
Date:   Tue Feb 10 16:17:12 2015 +0000

    Android: improve error handling in ownCloud provider.
    
    This provider now throws exceptions with properly internationalized
    messages to be shown to the user.
    
    Change-Id: I0464bffe14cab24d50180cb5e2e62ce746bcba74
    Reviewed-on: https://gerrit.libreoffice.org/16197
    Reviewed-by: Jacobo Aragunde Pérez <jaragu...@igalia.com>
    Tested-by: Jacobo Aragunde Pérez <jaragu...@igalia.com>

diff --git a/android/source/res/values/strings.xml 
b/android/source/res/values/strings.xml
index d2970b2..94ba49f 100644
--- a/android/source/res/values/strings.xml
+++ b/android/source/res/values/strings.xml
@@ -49,6 +49,10 @@
     <string name="local_file_system">Local file system</string>
     <string name="owncloud">ownCloud</string>
 
+    <string name="owncloud_wrong_connection">Cannot connect to ownCloud 
server. Check your configuration.</string>
+    <string name="owncloud_unauthorized">Cannot log into ownCloud server. 
Check your configuration.</string>
+    <string name="owncloud_unspecified_error">Unspecified error connecting to 
ownCloud server. Check your configuration and/or try later.</string>
+
     <!-- Edit action names -->
     <string name="action_bold">Bold</string>
     <string name="action_underline">Underline</string>
diff --git 
a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java 
b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java
index a8d1a06..ce10ab6 100644
--- a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java
+++ b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java
@@ -69,8 +69,7 @@ public class OwnCloudFile implements IFile {
             RemoteOperationResult result = refreshOperation.execute(provider
                     .getClient());
             if (!result.isSuccess()) {
-                throw new RuntimeException(result.getLogMessage(),
-                        result.getException());
+                throw 
provider.buildRuntimeExceptionForResultCode(result.getCode());
             }
             for (Object obj : result.getData()) {
                 RemoteFile child = (RemoteFile) obj;
@@ -104,7 +103,10 @@ public class OwnCloudFile implements IFile {
         File downFolder = provider.getCacheDir();
         DownloadRemoteFileOperation operation = new 
DownloadRemoteFileOperation(
                 file.getRemotePath(), downFolder.getAbsolutePath());
-        operation.execute(provider.getClient());
+        RemoteOperationResult result = operation.execute(provider.getClient());
+        if (!result.isSuccess()) {
+            throw 
provider.buildRuntimeExceptionForResultCode(result.getCode());
+        }
         return new File(downFolder.getAbsolutePath() + file.getRemotePath());
     }
 
diff --git 
a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
 
b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
index 827c0af..66e4633 100644
--- 
a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
+++ 
b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
@@ -18,6 +18,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.OwnCloudClientFactory;
 import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import 
com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
 import com.owncloud.android.lib.resources.files.FileUtils;
 import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation;
 import com.owncloud.android.lib.resources.files.RemoteFile;
@@ -78,8 +79,7 @@ public class OwnCloudProvider implements IDocumentProvider,
                 uri.getPath());
         RemoteOperationResult result = refreshOperation.execute(client);
         if (!result.isSuccess()) {
-            throw new RuntimeException(result.getLogMessage(),
-                    result.getException());
+            throw buildRuntimeExceptionForResultCode(result.getCode());
         }
         if (result.getData().size() > 0) {
             return new OwnCloudFile(this, (RemoteFile) 
result.getData().get(0));
@@ -113,6 +113,29 @@ public class OwnCloudProvider implements IDocumentProvider,
     }
 
     /**
+     * Build the proper RuntimeException for some error result.
+     *
+     * @param code Result code got from some RemoteOperationResult.
+     * @return exception with the proper internationalized error message.
+     */
+    protected RuntimeException buildRuntimeExceptionForResultCode(ResultCode 
code) {
+        int errorMessage;
+        switch (code) {
+            case WRONG_CONNECTION:  // SocketException
+            case FILE_NOT_FOUND:    // HTTP 404
+                errorMessage = R.string.owncloud_wrong_connection;
+                break;
+            case UNAUTHORIZED:      // wrong user/pass
+                errorMessage = R.string.owncloud_unauthorized;
+                break;
+            default:
+                errorMessage = R.string.owncloud_unspecified_error;
+                break;
+        }
+        return new RuntimeException(context.getString(errorMessage));
+    }
+
+    /**
      * Deletes files and recursively deletes directories.
      *
      * @param file
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to