AaU, I want to configure the timeouts used by the AWSApiPlugin.
See original GitHub issueI randomly get the following error when I send a request. (Regardless of GET, POST)
com.amplifyframework.api.ApiException: Received an IO exception while making the request.
Here’s my code:
fun <K, T> sendRequest(
request: K? = null, api: APIs,
queryMap: MutableMap<String, String>? = mutableMapOf(),
pathParameters: MutableMap<String, String>? = mutableMapOf(),
onSuccessAction: ((BaseResponse<T>) -> Unit)? = null
) {
showIndicator()
//Dynamic path parameters control
var editedEndpoint = api.endpoint
pathParameters?.forEach {
editedEndpoint = editedEndpoint.replace("{${it.key}}", it.value)
}
when (api.method) {
RequestMethod.POST -> {
val json = gson.toJson(request)
val bytes = json.toByteArray(StandardCharsets.UTF_8)
val options = RestOptions.builder()
.addPath(editedEndpoint)
.addBody(bytes)
.addHeaders(
mutableMapOf(
"Content-Type" to "application/json",
"Accept" to "application/json"
)
)
.addQueryParameters(queryMap ?: mapOf())
.build()
Amplify.API.post(options,
{ response ->
when {
response.code.isSuccessful -> {
val hasData = response.data.asJSONObject().isNull("data").not()
if (hasData && api.responseType != Empty::class.java) {
val typedData = gson.fromJson(
response.data.asJSONObject()["data"].toString(),
api.responseType
)
onSuccessAction?.invoke(BaseResponse(typedData) as BaseResponse<T>)
hideIndicator()
} else {
onSuccessAction?.invoke(BaseResponse(null))
hideIndicator()
}
}
response.code.isClientError -> {
}
response.code.isServiceFailure -> {
}
}
},
{
//API Error
})
}
RequestMethod.GET -> {
val options = RestOptions.builder()
.addPath(editedEndpoint)
.addHeaders(
mutableMapOf(
"Content-Type" to "application/x-www-form-urlencoded; charset=utf-8",
"Accept" to "application/json"
)
)
.addQueryParameters(queryMap ?: mapOf())
.build()
Amplify.API.get(options,
{ response ->
when {
response.code.isSuccessful -> {
val hasData = response.data.asJSONObject().isNull("data").not()
if (hasData && api.responseType != Empty::class.java) {
val typedData = gson.fromJson(
response.data.asJSONObject().optString("data"),
api.responseType
)
onSuccessAction?.invoke(BaseResponse(typedData) as BaseResponse<T>)
hideIndicator()
} else {
onSuccessAction?.invoke(BaseResponse(null))
hideIndicator()
}
}
response.code.isClientError -> {
}
response.code.isServiceFailure -> {
}
}
},
{
//API Error
})
}
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Customize Integration Timeouts in Amazon API Gateway
You can now customize the timeout value for API integrations in Amazon API Gateway. You can set the maximum amount of time an...
Read more >Configuring I/O timeout on Message Processors | Apigee Edge
This document explains how to configure the I/O timeout for the Apigee ... This property is used for all the API Proxies running...
Read more >Setting a Request Timeout for a Spring REST API
If we want to place a timeout on our database requests, we might want to use Spring's @Transactional method and its timeout property....
Read more >Always use a timeout for http requests
Many third party services we use in our apps provide APIs to be ... If we don't have a timeout set, our entire...
Read more >Retries and Timeouts | AWS SDK for Go V2
The AWS SDK for Go V2 enables you to configure the retry behavior of requests to HTTP services. By default, service clients use...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree this would be a good feature to include. Configurable timeouts is sort of a must-have for an API client. We will track enthusiasm according to user reactions on this ticket and will try to get it scheduled sooner or later. @aeraydogan Feel free to raise a PR! All in all we’d need:
amplifyconfiguration.json
readerIf the timeouts are not supplied in the
ampliflyconfiguration.json
, the current default values should be the same.Potentially, it might make sense to provide per-request timeout values in the options structure provided to
Amplify.API.whatever(...)
, too.Resolved in 1.17.0.