Skip to content

Commit 47eef1c

Browse files
authored
Merge pull request #3979 from owncloud/technical/add_error_handling_uploads
Add specific forbidden exception to transfer errors pool
2 parents 2b46548 + e921291 commit 47eef1c

4 files changed

Lines changed: 27 additions & 22 deletions

File tree

owncloudApp/src/main/java/com/owncloud/android/extensions/OCTransferExt.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fun OCTransfer.statusToStringRes(): Int {
5454
// Should not get here; status should be UPLOAD_SUCCESS
5555
TransferResult.UPLOADED -> R.string.uploads_view_upload_status_succeeded
5656
// We don't know the specific forbidden error message because it is not being saved in transfers storage
57-
TransferResult.SPECIFIC_FORBIDDEN -> R.string.uploader_upload_forbidden
57+
TransferResult.SPECIFIC_FORBIDDEN -> R.string.uploads_view_upload_status_failed_permission_error
5858
// We don't know the specific unavailable service error message because it is not being saved in transfers storage
5959
TransferResult.SPECIFIC_SERVICE_UNAVAILABLE -> R.string.service_unavailable
6060
// We don't know the specific unsupported media type error message because it is not being saved in transfers storage

owncloudApp/src/main/java/com/owncloud/android/extensions/ThrowableExt.kt

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import com.owncloud.android.domain.exceptions.ServerConnectionTimeoutException
4848
import com.owncloud.android.domain.exceptions.ServerNotReachableException
4949
import com.owncloud.android.domain.exceptions.ServerResponseTimeoutException
5050
import com.owncloud.android.domain.exceptions.ServiceUnavailableException
51+
import com.owncloud.android.domain.exceptions.SpecificForbiddenException
5152
import com.owncloud.android.domain.exceptions.UnauthorizedException
5253
import com.owncloud.android.domain.exceptions.validation.FileNameException
5354
import java.util.Locale
@@ -61,18 +62,12 @@ fun Throwable.parseError(
6162
return this.message as String
6263
} else { // Build the error message otherwise
6364
val reason = when (this) {
64-
is NoConnectionWithServerException -> resources.getString(R.string.network_error_socket_exception)
65-
is NoNetworkConnectionException -> resources.getString(R.string.error_no_network_connection)
66-
is ServerResponseTimeoutException -> resources.getString(R.string.network_error_socket_timeout_exception)
67-
is ServerConnectionTimeoutException -> resources.getString(R.string.network_error_connect_timeout_exception)
68-
is ServerNotReachableException -> resources.getString(R.string.network_host_not_available)
69-
is ServiceUnavailableException -> resources.getString(R.string.service_unavailable)
70-
is ConflictException -> resources.getString(R.string.error_conflict)
71-
is SSLRecoverablePeerUnverifiedException -> resources.getString(R.string.ssl_certificate_not_trusted)
65+
is AccountNotNewException -> resources.getString(R.string.auth_account_not_new)
66+
is AccountNotTheSameException -> resources.getString(R.string.auth_account_not_the_same)
7267
is BadOcVersionException -> resources.getString(R.string.auth_bad_oc_version_title)
73-
is IncorrectAddressException -> resources.getString(R.string.auth_incorrect_address_title)
74-
is SSLErrorException -> resources.getString(R.string.auth_ssl_general_error_title)
75-
is UnauthorizedException -> resources.getString(R.string.auth_unauthorized)
68+
is ConflictException -> resources.getString(R.string.error_conflict)
69+
is CopyIntoDescendantException -> resources.getString(R.string.copy_file_invalid_into_descendent)
70+
is CopyIntoSameFolderException -> resources.getString(R.string.copy_file_invalid_overwrite)
7671
is FileAlreadyExistsException -> resources.getString(R.string.file_already_exists)
7772
is FileNameException -> {
7873
val stringId = when (this.type) {
@@ -82,21 +77,28 @@ fun Throwable.parseError(
8277
}
8378
resources.getString(stringId)
8479
}
80+
is FileNotFoundException -> resources.getString(R.string.common_not_found)
81+
is ForbiddenException -> resources.getString(R.string.uploads_view_upload_status_failed_permission_error)
82+
is IncorrectAddressException -> resources.getString(R.string.auth_incorrect_address_title)
83+
is InstanceNotConfiguredException -> resources.getString(R.string.auth_not_configured_title)
8584
is InvalidOverwriteException -> resources.getString(R.string.file_already_exists)
85+
is LocalFileNotFoundException -> resources.getString(R.string.local_file_not_found_toast)
8686
is MoveIntoDescendantException -> resources.getString(R.string.move_file_invalid_into_descendent)
87-
is CopyIntoDescendantException -> resources.getString(R.string.copy_file_invalid_into_descendent)
8887
is MoveIntoSameFolderException -> resources.getString(R.string.move_file_invalid_overwrite)
89-
is CopyIntoSameFolderException -> resources.getString(R.string.copy_file_invalid_overwrite)
90-
is ForbiddenException -> resources.getString(R.string.forbidden_permissions, resources.getString(R.string.uploader_upload_forbidden_permissions))
91-
is FileNotFoundException -> resources.getString(R.string.common_not_found)
92-
is InstanceNotConfiguredException -> resources.getString(R.string.auth_not_configured_title)
93-
is OAuth2ErrorException -> resources.getString(R.string.auth_oauth_error)
88+
is NoConnectionWithServerException -> resources.getString(R.string.network_error_socket_exception)
89+
is NoNetworkConnectionException -> resources.getString(R.string.error_no_network_connection)
9490
is OAuth2ErrorAccessDeniedException -> resources.getString(R.string.auth_oauth_error_access_denied)
95-
is AccountNotNewException -> resources.getString(R.string.auth_account_not_new)
96-
is AccountNotTheSameException -> resources.getString(R.string.auth_account_not_the_same)
97-
is RedirectToNonSecureException -> resources.getString(R.string.auth_redirect_non_secure_connection_title)
98-
is LocalFileNotFoundException -> resources.getString(R.string.local_file_not_found_toast)
91+
is OAuth2ErrorException -> resources.getString(R.string.auth_oauth_error)
9992
is QuotaExceededException -> resources.getString(R.string.failed_upload_quota_exceeded_text)
93+
is RedirectToNonSecureException -> resources.getString(R.string.auth_redirect_non_secure_connection_title)
94+
is SSLErrorException -> resources.getString(R.string.auth_ssl_general_error_title)
95+
is SSLRecoverablePeerUnverifiedException -> resources.getString(R.string.ssl_certificate_not_trusted)
96+
is ServerConnectionTimeoutException -> resources.getString(R.string.network_error_connect_timeout_exception)
97+
is ServerNotReachableException -> resources.getString(R.string.network_host_not_available)
98+
is ServerResponseTimeoutException -> resources.getString(R.string.network_error_socket_timeout_exception)
99+
is ServiceUnavailableException -> resources.getString(R.string.service_unavailable)
100+
is SpecificForbiddenException -> resources.getString(R.string.uploads_view_upload_status_failed_permission_error)
101+
is UnauthorizedException -> resources.getString(R.string.auth_unauthorized)
100102
else -> resources.getString(R.string.common_error_unknown)
101103
}
102104

owncloudApp/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@
476476
<string name="network_host_not_available">Server could not be reached</string>
477477

478478
<string name="forbidden_permissions">You do not have permission %s</string>
479+
479480
<string name="forbidden_permissions_rename">to rename this file</string>
480481
<string name="forbidden_permissions_delete">to delete this file</string>
481482
<string name="share_link_forbidden_permissions">to share this file</string>

owncloudDomain/src/main/java/com/owncloud/android/domain/transfers/model/TransferResult.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.owncloud.android.domain.exceptions.NoConnectionWithServerException
2828
import com.owncloud.android.domain.exceptions.QuotaExceededException
2929
import com.owncloud.android.domain.exceptions.SSLRecoverablePeerUnverifiedException
3030
import com.owncloud.android.domain.exceptions.ServiceUnavailableException
31+
import com.owncloud.android.domain.exceptions.SpecificForbiddenException
3132
import com.owncloud.android.domain.exceptions.SpecificServiceUnavailableException
3233
import com.owncloud.android.domain.exceptions.SpecificUnsupportedMediaTypeException
3334
import com.owncloud.android.domain.exceptions.UnauthorizedException
@@ -85,6 +86,7 @@ enum class TransferResult constructor(val value: Int) {
8586
is FileNotFoundException -> FILE_NOT_FOUND
8687
is ConflictException -> CONFLICT_ERROR
8788
is ForbiddenException -> PRIVILEGES_ERROR
89+
is SpecificForbiddenException -> SPECIFIC_FORBIDDEN
8890
is ServiceUnavailableException -> SERVICE_UNAVAILABLE
8991
is SpecificServiceUnavailableException -> SPECIFIC_SERVICE_UNAVAILABLE
9092
is QuotaExceededException -> QUOTA_EXCEEDED

0 commit comments

Comments
 (0)