diff options
Diffstat (limited to 'android/source/src/java/org')
-rw-r--r-- | android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java | 8 | ||||
-rw-r--r-- | android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java | 27 |
2 files changed, 30 insertions, 5 deletions
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 |