Error RATE_LIMIT_EXCEEDED on SSR with Gatsby

Unfortunately, we have a problem. We switched to Server Side Rendering in a template at Gatsby. The static data comes in via gatsby-node.js, is then manipulated in getServerData for testing and then played out via serverData. The data is also safely static there. Unfortunately, we get rate limits from datocms all the time. Is it possible to see which queries exactly are causing the rate limits? Thanks :slight_smile:

1 Like

Hey @website

You can see the queries that are causing the rate-limit as they return a 429 response.
However, since you are using an on-build static solution, we can completely go arround the rate limit with a simple solution:

A good solution is to wrap the request-making process in a function that re-attempts the request if the rate limit is currently exceeded, this way you can make sure that on build-time all of the requests will go through and be successful, even if the rate-limit is temporarily reached.

A simple recursive function where the termination condition is the 200 response should work, otherwise it calls itself again and attempts the call once again.

Something like (in pseudocode):

const makeGraphQLRequest = async (query) => { const response = await fetch(query); if (response.code === 200) { return response; } return makeGraphQLRequest(query); };

Or, for a non-recursive approach:

const makeGraphQLRequest = async (query) => { let response; do { response = await fetch(query); } while (response.code !== 200); return response; };

Depending on the amount of concurrent requests, perhaps adding a delay between request attempts may be a good idea.

1 Like

Thanks for the quick reply!

We will try this out and test it live :slight_smile: