twilio / twilio-node

Node.js helper library
MIT License
1.37k stars 495 forks source link

Feature Request: Add hook for 429 retry logic #936

Open ccwurtz opened 1 year ago

ccwurtz commented 1 year ago

Description

Currently, if configured the twilio-node library automatically retries requests when it encounters a 429 error, but there's no way to be notified or modify this behavior.

Proposal

Add an optional onRetry parameter to the twilio() function that accepts a callback to be called whenever a 429 error is encountered. This would allow users to handle or log these errors in a custom way.

Example usage:

import { Twilio } from 'twilio';

const client = new Twilio(accountSid, authToken, {
  onRetry: (attempt: number, delay: number) => {
    console.log(`Retrying after ${delay}ms (attempt ${attempt})`);
    return true; // continue with retry
  },
});

I'd be happy to submit a PR to implement this.

AsabuHere commented 1 year ago

Hi @ccwurtz, Thank you for the heads up! We have added this enhancement request to our backlog. Pull requests and +1s on the issue will help it move up the backlog. It would be great if you can submit a PR implementing this

Thanks, Athira

GuiSim commented 5 months ago

Scope creeping here: But having the ability to choose which error codes should be retried would help. As multiple people have reported in this repository over time, Twilio's API sometimes throws a 404 for a valid request and I'd like to see these retried automatically.