Best answer

Control number of retries with z.errors.ThrottledError

  • 22 February 2023
  • 1 reply
  • 127 views

Userlevel 1

I read about the example below, but I am worried about infinite retries if somehow the server keeps returning 429s. 

  • Is there a default limit on the number of retry?
  • Is there a way to control the number of retries from a throttledError?

 

https://github.com/zapier/zapier-platform/blob/main/packages/cli/README.md#handling-throttled-requests

const yourAfterResponse = (resp) => {  if (resp.status === 429) {    throw new z.errors.ThrottledError('message here', 60);  // Zapier will retry in 60 seconds  }  return resp;};
icon

Best answer by MarinaH 2 March 2023, 23:48

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Userlevel 4
Badge +9

Hi @boinlabs 👋

There is no way to specify the number of retries with the z.errors.ThrottledError - however the number of retries would not be infinite.

A high volume of errors can cause a Zap to get turned off. More info on how throttling applies and how it is shown to the user can be found here: https://platform.zapier.com/docs/constraints#throttling-your-api  

Note that throttling applies per individual run per user. So if a Zap action is being attempted multiple times consecutively (if the trigger on that Zap fires many times for example), each will be throttled independent of the others.

It is an option to use the custom error handling method z.errors.Error: https://github.com/zapier/zapier-platform/blob/main/packages/cli/README.md#general-errors so the Zap throws an error in response to a 429. That would prevent any retries all together but this may not be desirable for your users. 

If the concern is too many attempts to retry all at once hitting the API limit and repeatedly receiving a 429; one idea some partners have tried is to implement your own "jitter", if you do want Zaps to be able to retry, but not all at once. That could look something like this:
 
throw new z.errors.ThrottledError('message here', 60 + Math.floor(Math.random() * 60))

and make it so that the retry would occur between 1 and 2 minutes from the time the 429 error is received, and you can adjust those numbers as needed.