twilio-node
twilio-node copied to clipboard
Expose timeout to the public Twilio constructor
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
Interested , please assign this to me
@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.
1++;
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
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 }),
});