Skip to content

Commit 18ac85c

Browse files
authored
Merge pull request #4685 from owncloud/fix/handle_413_http_response_code
[FIX] Handling of HTTP response code 413
2 parents ead4576 + 0e9aaaf commit 18ac85c

File tree

9 files changed

+63
-6
lines changed

9 files changed

+63
-6
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ ownCloud admins and users.
3939

4040
## Summary
4141

42+
* Bugfix - Handling of HTTP code response 413: [#4094](https://github.com/owncloud/android/issues/4094)
4243
* Bugfix - Set authorization header for token request only when necessary: [#4575](https://github.com/owncloud/android/issues/4575)
4344
* Bugfix - Add explicit permission to Detekt workflow: [#4675](https://github.com/owncloud/android/pull/4675)
4445
* Change - SBOM workflow runs on dependabot PRs: [#4664](https://github.com/owncloud/android/pull/4664)
@@ -51,6 +52,14 @@ ownCloud admins and users.
5152

5253
## Details
5354

55+
* Bugfix - Handling of HTTP code response 413: [#4094](https://github.com/owncloud/android/issues/4094)
56+
57+
A new exception has been added to handle cases where the payload exceeds the
58+
server limit (HTTP code 413)
59+
60+
https://github.com/owncloud/android/issues/4094
61+
https://github.com/owncloud/android/pull/4685
62+
5463
* Bugfix - Set authorization header for token request only when necessary: [#4575](https://github.com/owncloud/android/issues/4575)
5564

5665
A new field has been added to the token request to indicate whether the

changelog/unreleased/4685

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Bugfix: Handling of HTTP code response 413
2+
3+
A new exception has been added to handle cases where the payload exceeds the server limit (HTTP code 413)
4+
5+
https://github.com/owncloud/android/issues/4094
6+
https://github.com/owncloud/android/pull/4685

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* ownCloud Android client application
33
*
44
* @author Juan Carlos Garrote Gascón
5+
* @author Jorge Aguado Recio
56
*
6-
* Copyright (C) 2022 ownCloud GmbH.
7+
* Copyright (C) 2025 ownCloud GmbH.
78
*
89
* This program is free software: you can redistribute it and/or modify
910
* it under the terms of the GNU General Public License version 2,
@@ -49,6 +50,7 @@ fun OCTransfer.statusToStringRes(): Int =
4950
TransferResult.QUOTA_EXCEEDED -> R.string.failed_upload_quota_exceeded_text
5051
TransferResult.SSL_RECOVERABLE_PEER_UNVERIFIED -> R.string.ssl_certificate_not_trusted
5152
TransferResult.UNKNOWN -> R.string.uploads_view_upload_status_unknown_fail
53+
TransferResult.FILE_TOO_LARGE -> R.string.uploads_view_upload_status_failed_payload_error
5254
// Should not get here; cancelled uploads should be wiped out
5355
TransferResult.CANCELLED -> R.string.uploads_view_upload_status_cancelled
5456
// Should not get here; status should be UPLOAD_SUCCESS

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
* ownCloud Android client application
33
*
44
* @author David González Verdugo
5-
* Copyright (C) 2020 ownCloud GmbH.
5+
* @author Jorge Aguado Recio
6+
*
7+
* Copyright (C) 2025 ownCloud GmbH.
68
*
79
* This program is free software: you can redistribute it and/or modify
810
* it under the terms of the GNU General Public License version 2,
@@ -41,6 +43,7 @@ import com.owncloud.android.domain.exceptions.NoConnectionWithServerException
4143
import com.owncloud.android.domain.exceptions.NoNetworkConnectionException
4244
import com.owncloud.android.domain.exceptions.OAuth2ErrorAccessDeniedException
4345
import com.owncloud.android.domain.exceptions.OAuth2ErrorException
46+
import com.owncloud.android.domain.exceptions.PayloadTooLongException
4447
import com.owncloud.android.domain.exceptions.QuotaExceededException
4548
import com.owncloud.android.domain.exceptions.RedirectToNonSecureException
4649
import com.owncloud.android.domain.exceptions.ResourceLockedException
@@ -100,6 +103,7 @@ fun Throwable.parseError(
100103
is UnauthorizedException -> resources.getString(R.string.auth_unauthorized)
101104
is NetworkErrorException -> resources.getString(R.string.network_error_message)
102105
is ResourceLockedException -> resources.getString(R.string.resource_locked_error_message)
106+
is PayloadTooLongException -> resources.getString(R.string.uploads_view_upload_status_failed_payload_error)
103107
else -> resources.getString(R.string.common_error_unknown)
104108
}
105109

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@
260260
<string name="uploads_view_upload_status_failed_localfile_error">Local file not found</string>
261261
<string name="uploads_view_upload_status_failed_permission_error">Permission error</string>
262262
<string name="uploads_view_upload_status_failed_firewall_error">Forbidden due to a firewall rule</string>
263+
<string name="uploads_view_upload_status_failed_payload_error">File too large for upload</string>
263264
<string name="uploads_view_upload_status_conflict">Conflict</string>
264265
<string name="uploads_view_upload_status_service_interrupted">App was terminated</string>
265266
<string name="uploads_view_upload_status_unknown_fail">Unknown error</string>

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ public RemoteOperationResult(HttpBaseMethod httpMethod) throws IOException {
244244
case HttpConstants.HTTP_TOO_EARLY:
245245
mCode = ResultCode.TOO_EARLY;
246246
break;
247+
case HttpConstants.HTTP_REQUEST_TOO_LONG:
248+
mCode = ResultCode.PAYLOAD_TOO_LONG;
249+
break;
247250
default:
248251
break;
249252
}
@@ -596,6 +599,7 @@ public enum ResultCode {
596599
SPECIFIC_BAD_REQUEST,
597600
TOO_EARLY,
598601
NETWORK_ERROR,
599-
RESOURCE_LOCKED
602+
RESOURCE_LOCKED,
603+
PAYLOAD_TOO_LONG
600604
}
601605
}

owncloudData/src/main/java/com/owncloud/android/data/RemoteOperationHandler.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
*
44
* @author David González Verdugo
55
* @author Juan Carlos Garrote Gascón
6+
* @author Jorge Aguado Recio
67
*
7-
* Copyright (C) 2022 ownCloud GmbH.
8+
* Copyright (C) 2025 ownCloud GmbH.
89
*
910
* This program is free software: you can redistribute it and/or modify
1011
* it under the terms of the GNU General Public License version 2,
@@ -51,6 +52,7 @@ import com.owncloud.android.domain.exceptions.OAuth2ErrorAccessDeniedException
5152
import com.owncloud.android.domain.exceptions.OAuth2ErrorException
5253
import com.owncloud.android.domain.exceptions.PartialCopyDoneException
5354
import com.owncloud.android.domain.exceptions.PartialMoveDoneException
55+
import com.owncloud.android.domain.exceptions.PayloadTooLongException
5456
import com.owncloud.android.domain.exceptions.QuotaExceededException
5557
import com.owncloud.android.domain.exceptions.RedirectToNonSecureException
5658
import com.owncloud.android.domain.exceptions.ResourceLockedException
@@ -143,6 +145,7 @@ private fun <T> handleRemoteOperationResult(
143145
RemoteOperationResult.ResultCode.TOO_EARLY -> throw TooEarlyException()
144146
RemoteOperationResult.ResultCode.NETWORK_ERROR -> throw NetworkErrorException()
145147
RemoteOperationResult.ResultCode.RESOURCE_LOCKED -> throw ResourceLockedException()
148+
RemoteOperationResult.ResultCode.PAYLOAD_TOO_LONG -> throw PayloadTooLongException()
146149
else -> throw Exception("An unknown error has occurred")
147150
}
148151
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* ownCloud Android client application
3+
*
4+
* @author Jorge Aguado Recio
5+
*
6+
* Copyright (C) 2025 ownCloud GmbH.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2,
10+
* as published by the Free Software Foundation.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
package com.owncloud.android.domain.exceptions
22+
23+
class PayloadTooLongException : Exception()

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* ownCloud Android client application
33
*
44
* @author Juan Carlos Garrote Gascón
5+
* @author Jorge Aguado Recio
56
*
6-
* Copyright (C) 2022 ownCloud GmbH.
7+
* Copyright (C) 2025 ownCloud GmbH.
78
*
89
* This program is free software: you can redistribute it and/or modify
910
* it under the terms of the GNU General Public License version 2,
@@ -26,6 +27,7 @@ import com.owncloud.android.domain.exceptions.ForbiddenException
2627
import com.owncloud.android.domain.exceptions.LocalFileNotFoundException
2728
import com.owncloud.android.domain.exceptions.NetworkErrorException
2829
import com.owncloud.android.domain.exceptions.NoConnectionWithServerException
30+
import com.owncloud.android.domain.exceptions.PayloadTooLongException
2931
import com.owncloud.android.domain.exceptions.QuotaExceededException
3032
import com.owncloud.android.domain.exceptions.SSLRecoverablePeerUnverifiedException
3133
import com.owncloud.android.domain.exceptions.ServiceUnavailableException
@@ -52,7 +54,8 @@ enum class TransferResult constructor(val value: Int) {
5254
SSL_RECOVERABLE_PEER_UNVERIFIED(value = 13),
5355
SPECIFIC_FORBIDDEN(value = 14),
5456
SPECIFIC_SERVICE_UNAVAILABLE(value = 15),
55-
SPECIFIC_UNSUPPORTED_MEDIA_TYPE(value = 16);
57+
SPECIFIC_UNSUPPORTED_MEDIA_TYPE(value = 16),
58+
FILE_TOO_LARGE(value = 17);
5659

5760
companion object {
5861
fun fromValue(value: Int): TransferResult =
@@ -74,6 +77,7 @@ enum class TransferResult constructor(val value: Int) {
7477
14 -> SPECIFIC_FORBIDDEN
7578
15 -> SPECIFIC_SERVICE_UNAVAILABLE
7679
16 -> SPECIFIC_UNSUPPORTED_MEDIA_TYPE
80+
17 -> FILE_TOO_LARGE
7781
else -> UNKNOWN
7882
}
7983

@@ -94,6 +98,7 @@ enum class TransferResult constructor(val value: Int) {
9498
is QuotaExceededException -> QUOTA_EXCEEDED
9599
is SpecificUnsupportedMediaTypeException -> SPECIFIC_UNSUPPORTED_MEDIA_TYPE
96100
is SSLRecoverablePeerUnverifiedException -> SSL_RECOVERABLE_PEER_UNVERIFIED
101+
is PayloadTooLongException -> FILE_TOO_LARGE
97102
else -> UNKNOWN
98103
}
99104
}

0 commit comments

Comments
 (0)