Skip to content

Commit

Permalink
Add react to request throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
CheK539 committed Oct 31, 2023
1 parent b32902a commit f2fcfc6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
- Added support for new event types of webhooks.
- Removed sorting methods by file size, as the corresponding parameter has been removed from
the API query parameters.
- Added react to request throttling (429 code answer)
- Widget:
- SocialApi doesn't use `GET /sources` method anymore.
- Project:
- Migrated Gradle builds from Groovy to Kotlin.
- Example:
- Removed sorting options by file size from `UploadFragment`.


## 3.3.0
- Library:
- Added support for [signing your webhooks](https://uploadcare.com/docs/webhooks/#signed-webhooks) using the `signingSecret` parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.uploadcare.android.library.data.PageData
import com.uploadcare.android.library.exceptions.UploadcareApiException
import com.uploadcare.android.library.exceptions.UploadcareAuthenticationException
import com.uploadcare.android.library.exceptions.UploadcareInvalidRequestException
import com.uploadcare.android.library.exceptions.UploadcareRequestThrottlingException
import com.uploadcare.android.library.urls.UrlParameter
import com.uploadcare.android.library.urls.UrlUtils.Companion.trustedBuild
import com.uploadcare.android.library.urls.Urls
Expand Down Expand Up @@ -603,6 +604,9 @@ class RequestHelper(private val client: UploadcareClient) {
throw UploadcareAuthenticationException("$response")
} else if (statusCode == 400 || statusCode == 404) {
throw UploadcareInvalidRequestException("$response")
} else if (statusCode == 429) {
val retryTimeout = response.header("Retry-After")?.toLong() ?: 0
throw UploadcareRequestThrottlingException("$response", retryTimeout)
} else {
throw UploadcareApiException(
"Unknown exception during an API call, response: $response")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ class UploadFailureException : UploadcareApiException {
constructor(message: String, cause: Throwable) : super(message, cause)
}

class UploadcareRequestThrottlingException(
message: String?,
val retryTimeout: Long
) : UploadcareApiException(message)

internal class UploadPausedException(message: String?): UploadcareApiException(message)

0 comments on commit f2fcfc6

Please sign in to comment.