diff options
author | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2015-02-10 16:17:12 +0000 |
---|---|---|
committer | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2015-06-10 17:18:50 +0000 |
commit | 78ecdbc2f69b9d812cf879f662e7c1277d3c9b07 (patch) | |
tree | 989f221cca01a39989b386aa583b07eaf1585c63 /android | |
parent | f8a4e1aab608538567562d97e6da60f015337c47 (diff) |
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 <jaragunde@igalia.com>
Tested-by: Jacobo Aragunde Pérez <jaragunde@igalia.com>
Diffstat (limited to 'android')
3 files changed, 34 insertions, 5 deletions
diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml index d2970b28c4d8..94ba49f7b148 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 a8d1a06e3092..ce10ab64a1e6 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 827c0aff22d4..66e4633fe5c6 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 |