summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacobo Aragunde Pérez <jaragunde@igalia.com>2015-02-10 16:17:12 +0000
committerJacobo Aragunde Pérez <jaragunde@igalia.com>2015-06-03 17:21:23 +0000
commitb31d175eb982a8c95e89d051e723cb843af2d1a0 (patch)
tree555aa04a72f14ea868c4944fb469f289f1cf457e
parentd163cd957a1c3e2df6e6a4e587b31af6c802fb75 (diff)
Android: improve error handling in ownCloud provider.feature/owncloud-provider-for-android
This provider now throws exceptions with properly internationalized messages to be shown to the user. Change-Id: I0464bffe14cab24d50180cb5e2e62ce746bcba74
-rw-r--r--android/experimental/LOAndroid3/res/values/strings.xml4
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java8
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java27
3 files changed, 34 insertions, 5 deletions
diff --git a/android/experimental/LOAndroid3/res/values/strings.xml b/android/experimental/LOAndroid3/res/values/strings.xml
index 336b19b24105..135e52dc80df 100644
--- a/android/experimental/LOAndroid3/res/values/strings.xml
+++ b/android/experimental/LOAndroid3/res/values/strings.xml
@@ -36,6 +36,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>
+
<!-- Document provider settings -->
<string name="storage_provider_settings">Storage provider settings</string>
<string name="owncloud_settings">ownCloud settings</string>
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java
index a8d1a06e3092..ce10ab64a1e6 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java
+++ b/android/experimental/LOAndroid3/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/experimental/LOAndroid3/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
index 827c0aff22d4..66e4633fe5c6 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
+++ b/android/experimental/LOAndroid3/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