twilio-node icon indicating copy to clipboard operation
twilio-node copied to clipboard

Expose timeout to the public Twilio constructor

Open samuelg opened this issue 4 years ago • 4 comments

Issue Summary

Today the internal RestClient exposes a way to customize the timeout used for API requests. However the public Twilio constructor does not expose an option for us to customize this. Our only option is to implement a completely custom HTTP client (which we would need to continue to change to match this library's implementation) and then pass that using the httpClient option on the public Twilio constructor. We would like to continue to rely on the internal HTTP client this library uses but be able to pass a custom timeout, which would then be used internally when creating an instance of RestClient.

Code Snippet

// Instead of the following
twilio(sid, token, { httpClient: completelyCustomHttpClient });
// Something like this
twilio(sid, token, { timeout: 10000 });

Technical details:

  • twilio-node version: 3.43.0
  • node version: 12.18.0

samuelg avatar Sep 14 '20 23:09 samuelg

Interested , please assign this to me

gagandeepp avatar Sep 15 '20 05:09 gagandeepp

@gagandeepp If you're interested in addressing this issue, please feel free to submit a PR with the fix and we'll add it to our backlog for review. This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

eshanholtz avatar Sep 18 '20 23:09 eshanholtz

1++;

ruslanrusu avatar Feb 16 '21 23:02 ruslanrusu

I came across this need today, because looking up a number's carrier type was sometimes taking 2 minutes (which far exceeds Twilio's 15-second response timeout during a call). To work around it, I just used a Promise timeout:

Promise.resolve()
  .then(() => twilio.fetch()...)
  .then(() => // do stuff)
  .timeout(SOME_NUMBER); // bluebird, or can use Promise.race() or other timeout alternatives

6utt3rfly avatar Apr 06 '22 20:04 6utt3rfly

Fixed by https://github.com/twilio/twilio-node/pull/668 and https://github.com/twilio/twilio-node/pull/775

Example usage:

const Twilio = require("twilio");
const { RequestClient } = Twilio;

const twilioClient = new Twilio(accountSid, authToken, {
  httpClient: new RequestClient({ timeout: 10000 }),
});

childish-sambino avatar Nov 28 '22 17:11 childish-sambino