diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b4c6c3aa03..8c72c25d5f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ ownCloud admins and users. ## Summary +* Bugfix - Handling of HTTP code response 413: [#4094](https://github.com/owncloud/android/issues/4094) * Bugfix - Set authorization header for token request only when necessary: [#4575](https://github.com/owncloud/android/issues/4575) * Bugfix - Add explicit permission to Detekt workflow: [#4675](https://github.com/owncloud/android/pull/4675) * Change - SBOM workflow runs on dependabot PRs: [#4664](https://github.com/owncloud/android/pull/4664) @@ -51,6 +52,14 @@ ownCloud admins and users. ## Details +* Bugfix - Handling of HTTP code response 413: [#4094](https://github.com/owncloud/android/issues/4094) + + A new exception has been added to handle cases where the payload exceeds the + server limit (HTTP code 413) + + https://github.com/owncloud/android/issues/4094 + https://github.com/owncloud/android/pull/4685 + * Bugfix - Set authorization header for token request only when necessary: [#4575](https://github.com/owncloud/android/issues/4575) A new field has been added to the token request to indicate whether the diff --git a/changelog/unreleased/4685 b/changelog/unreleased/4685 new file mode 100644 index 00000000000..b4755352896 --- /dev/null +++ b/changelog/unreleased/4685 @@ -0,0 +1,6 @@ +Bugfix: Handling of HTTP code response 413 + +A new exception has been added to handle cases where the payload exceeds the server limit (HTTP code 413) + +https://github.com/owncloud/android/issues/4094 +https://github.com/owncloud/android/pull/4685 diff --git a/owncloudApp/src/main/java/com/owncloud/android/extensions/OCTransferExt.kt b/owncloudApp/src/main/java/com/owncloud/android/extensions/OCTransferExt.kt index 59c0fa4deda..a0b6b884bdc 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/extensions/OCTransferExt.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/extensions/OCTransferExt.kt @@ -2,8 +2,9 @@ * ownCloud Android client application * * @author Juan Carlos Garrote Gascón + * @author Jorge Aguado Recio * - * Copyright (C) 2022 ownCloud GmbH. + * Copyright (C) 2025 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -49,6 +50,7 @@ fun OCTransfer.statusToStringRes(): Int = TransferResult.QUOTA_EXCEEDED -> R.string.failed_upload_quota_exceeded_text TransferResult.SSL_RECOVERABLE_PEER_UNVERIFIED -> R.string.ssl_certificate_not_trusted TransferResult.UNKNOWN -> R.string.uploads_view_upload_status_unknown_fail + TransferResult.FILE_TOO_LARGE -> R.string.uploads_view_upload_status_failed_payload_error // Should not get here; cancelled uploads should be wiped out TransferResult.CANCELLED -> R.string.uploads_view_upload_status_cancelled // Should not get here; status should be UPLOAD_SUCCESS diff --git a/owncloudApp/src/main/java/com/owncloud/android/extensions/ThrowableExt.kt b/owncloudApp/src/main/java/com/owncloud/android/extensions/ThrowableExt.kt index fd0eebe6880..1ec48e55598 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/extensions/ThrowableExt.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/extensions/ThrowableExt.kt @@ -2,7 +2,9 @@ * ownCloud Android client application * * @author David González Verdugo - * Copyright (C) 2020 ownCloud GmbH. + * @author Jorge Aguado Recio + * + * Copyright (C) 2025 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -41,6 +43,7 @@ import com.owncloud.android.domain.exceptions.NoConnectionWithServerException import com.owncloud.android.domain.exceptions.NoNetworkConnectionException import com.owncloud.android.domain.exceptions.OAuth2ErrorAccessDeniedException import com.owncloud.android.domain.exceptions.OAuth2ErrorException +import com.owncloud.android.domain.exceptions.PayloadTooLongException import com.owncloud.android.domain.exceptions.QuotaExceededException import com.owncloud.android.domain.exceptions.RedirectToNonSecureException import com.owncloud.android.domain.exceptions.ResourceLockedException @@ -100,6 +103,7 @@ fun Throwable.parseError( is UnauthorizedException -> resources.getString(R.string.auth_unauthorized) is NetworkErrorException -> resources.getString(R.string.network_error_message) is ResourceLockedException -> resources.getString(R.string.resource_locked_error_message) + is PayloadTooLongException -> resources.getString(R.string.uploads_view_upload_status_failed_payload_error) else -> resources.getString(R.string.common_error_unknown) } diff --git a/owncloudApp/src/main/res/values/strings.xml b/owncloudApp/src/main/res/values/strings.xml index 2d53a2088aa..943d5d95045 100644 --- a/owncloudApp/src/main/res/values/strings.xml +++ b/owncloudApp/src/main/res/values/strings.xml @@ -260,6 +260,7 @@ Local file not found Permission error Forbidden due to a firewall rule + File too large for upload Conflict App was terminated Unknown error diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index 7cb54ba622e..a47e823542b 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -244,6 +244,9 @@ public RemoteOperationResult(HttpBaseMethod httpMethod) throws IOException { case HttpConstants.HTTP_TOO_EARLY: mCode = ResultCode.TOO_EARLY; break; + case HttpConstants.HTTP_REQUEST_TOO_LONG: + mCode = ResultCode.PAYLOAD_TOO_LONG; + break; default: break; } @@ -596,6 +599,7 @@ public enum ResultCode { SPECIFIC_BAD_REQUEST, TOO_EARLY, NETWORK_ERROR, - RESOURCE_LOCKED + RESOURCE_LOCKED, + PAYLOAD_TOO_LONG } } diff --git a/owncloudData/src/main/java/com/owncloud/android/data/RemoteOperationHandler.kt b/owncloudData/src/main/java/com/owncloud/android/data/RemoteOperationHandler.kt index fcfe3c876b1..94902458ce5 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/RemoteOperationHandler.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/RemoteOperationHandler.kt @@ -3,8 +3,9 @@ * * @author David González Verdugo * @author Juan Carlos Garrote Gascón + * @author Jorge Aguado Recio * - * Copyright (C) 2022 ownCloud GmbH. + * Copyright (C) 2025 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -51,6 +52,7 @@ import com.owncloud.android.domain.exceptions.OAuth2ErrorAccessDeniedException import com.owncloud.android.domain.exceptions.OAuth2ErrorException import com.owncloud.android.domain.exceptions.PartialCopyDoneException import com.owncloud.android.domain.exceptions.PartialMoveDoneException +import com.owncloud.android.domain.exceptions.PayloadTooLongException import com.owncloud.android.domain.exceptions.QuotaExceededException import com.owncloud.android.domain.exceptions.RedirectToNonSecureException import com.owncloud.android.domain.exceptions.ResourceLockedException @@ -143,6 +145,7 @@ private fun handleRemoteOperationResult( RemoteOperationResult.ResultCode.TOO_EARLY -> throw TooEarlyException() RemoteOperationResult.ResultCode.NETWORK_ERROR -> throw NetworkErrorException() RemoteOperationResult.ResultCode.RESOURCE_LOCKED -> throw ResourceLockedException() + RemoteOperationResult.ResultCode.PAYLOAD_TOO_LONG -> throw PayloadTooLongException() else -> throw Exception("An unknown error has occurred") } } diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/exceptions/PayloadTooLongException.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/exceptions/PayloadTooLongException.kt new file mode 100644 index 00000000000..f71893151d7 --- /dev/null +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/exceptions/PayloadTooLongException.kt @@ -0,0 +1,23 @@ +/** + * ownCloud Android client application + * + * @author Jorge Aguado Recio + * + * Copyright (C) 2025 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.domain.exceptions + +class PayloadTooLongException : Exception() diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/transfers/model/TransferResult.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/transfers/model/TransferResult.kt index 1aa0a338a09..511391c7300 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/transfers/model/TransferResult.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/transfers/model/TransferResult.kt @@ -2,8 +2,9 @@ * ownCloud Android client application * * @author Juan Carlos Garrote Gascón + * @author Jorge Aguado Recio * - * Copyright (C) 2022 ownCloud GmbH. + * Copyright (C) 2025 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -26,6 +27,7 @@ import com.owncloud.android.domain.exceptions.ForbiddenException import com.owncloud.android.domain.exceptions.LocalFileNotFoundException import com.owncloud.android.domain.exceptions.NetworkErrorException import com.owncloud.android.domain.exceptions.NoConnectionWithServerException +import com.owncloud.android.domain.exceptions.PayloadTooLongException import com.owncloud.android.domain.exceptions.QuotaExceededException import com.owncloud.android.domain.exceptions.SSLRecoverablePeerUnverifiedException import com.owncloud.android.domain.exceptions.ServiceUnavailableException @@ -52,7 +54,8 @@ enum class TransferResult constructor(val value: Int) { SSL_RECOVERABLE_PEER_UNVERIFIED(value = 13), SPECIFIC_FORBIDDEN(value = 14), SPECIFIC_SERVICE_UNAVAILABLE(value = 15), - SPECIFIC_UNSUPPORTED_MEDIA_TYPE(value = 16); + SPECIFIC_UNSUPPORTED_MEDIA_TYPE(value = 16), + FILE_TOO_LARGE(value = 17); companion object { fun fromValue(value: Int): TransferResult = @@ -74,6 +77,7 @@ enum class TransferResult constructor(val value: Int) { 14 -> SPECIFIC_FORBIDDEN 15 -> SPECIFIC_SERVICE_UNAVAILABLE 16 -> SPECIFIC_UNSUPPORTED_MEDIA_TYPE + 17 -> FILE_TOO_LARGE else -> UNKNOWN } @@ -94,6 +98,7 @@ enum class TransferResult constructor(val value: Int) { is QuotaExceededException -> QUOTA_EXCEEDED is SpecificUnsupportedMediaTypeException -> SPECIFIC_UNSUPPORTED_MEDIA_TYPE is SSLRecoverablePeerUnverifiedException -> SSL_RECOVERABLE_PEER_UNVERIFIED + is PayloadTooLongException -> FILE_TOO_LARGE else -> UNKNOWN } }