Next.js Discord

Discord Forum

how to handle HTTP 429 too many requests

Unanswered
Yakutian Laika posted this in #help-forum
Open in Discord
Yakutian LaikaOP
I have a page that makes a fetch request to an endpoint and when the seo team triggers the tools to analyze the site that endpoint returns an HTTP 429 error.

When I get the response from the fetch call I can check the status code and actually I can display to the user whatever I want...

But what I need to do when I get the http 429 is to return this same error in Next.js so Google can know is not a 404, 500 or any 200 success code.

I need to tell the browser the page in next.js is doing a 429 and set a retry later header

1 Reply

Yakutian LaikaOP
I tried to move the fetch call into a route handler and call it from the page component, the result is the same, I can return a 429 from the route handler but the page still returns a 200...

Asking gpt or v0 don't help, both answered checking the status code in the page component and:
1. throw an error and setting the code to 429 but the page resolves into a 500
2. use NextResponse to return an object which results into a 500 because components cannot return an object