how to set timeout from frontend in apigClient aws

人盡茶涼 提交于 2019-12-24 20:32:17

问题


I'm working with the amazon api client gateway.it works fine with all the request and response. Now I want to add some timeout, I tried this:


        apigClient.method(params, body, additionalParams)
        .timeout(1000)
        .then(function (result) {
            //succcess part
        }).catch(function (err) {
            //error part
    });`

But It doest work. I got this message from my console "error: apigClient.method(...).timeout is not a function"


回答1:


The generated JS client doesn't support custom timeout by default, but you can add your own timeout logic on top of the client with very minimal modification since the underlying HTTP client is supporting client side timeout in the request object.

Suggested modification

diff --git a/apigClient.js b/apigClient.js
index 6f900b3..8977fb1 100755
--- a/apigClient.js
+++ b/apigClient.js
@@ -93,7 +93,8 @@ apigClientFactory.newClient = function (config) {
             path: pathComponent + uritemplate('/').expand(apiGateway.core.utils.parseParametersToObject(params, [])),
             headers: apiGateway.core.utils.parseParametersToObject(params, []),
             queryParams: apiGateway.core.utils.parseParametersToObject(params, ['test']),
-            body: body
+            body: body,
+            timout: 1000 // milliseconds
         };


diff --git a/lib/apiGatewayCore/simpleHttpClient.js b/lib/apiGatewayCore/simpleHttpClient.js
index 3fb1e5a..6a37a93 100755
--- a/lib/apiGatewayCore/simpleHttpClient.js
+++ b/lib/apiGatewayCore/simpleHttpClient.js
@@ -73,7 +73,8 @@ apiGateway.core.simpleHttpClientFactory.newClient = function (config) {
             method: verb,
             url: url,
             headers: headers,
-            data: body
+            data: body,
+            timeout: request.timeout
         };
         return axios(simpleHttpRequest);
     };



回答2:


I called to AWS support and I got this answer:

Hello, Thanks for taking the timeout to chat with us!

Here's a summary of our chat: You are looking fr a way to set timeouts while making requests to API gateway >from your apigClient SDK. Setting timeouts in API Gateway is not possible as API >Gateway has a hard limit of 30 seconds as a timeout for any type of integration. >For details on this, please refer: http://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html

However, automatic retries are implemented from the SDKs. For details on the >retry logic with exponential backoffs, please refer to the documentation: http://docs.aws.amazon.com/general/latest/gr/api-retries.html

Please get back to me if you have any questions and I'd be happy to assist you.

I hope this helps!!!



来源:https://stackoverflow.com/questions/45382717/how-to-set-timeout-from-frontend-in-apigclient-aws

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!