Custom 429 page?

Hello! Right, so I’m looking to create custom error pages for common error codes, I have the 404 and I’d like to do the 429 too many requests now - is there a way to do this? I am ising express, but I don’t really know how it works. Any help would be greatly appreciated! Thanks in advance!

Thats a good question!

This will do the trick:

app.get('/', (req, res) => res.send('429 Error', 429))

Using curl -I (glitch site) I got:
HTTP/1.1 429 Too Many Requests

Hey there, you can do what RiversideRocks mentioned or use res.status(429).send("Too Many Requests")

@ItsYanko @RiversideRocks He is asking for a custom 429 page, with his own HTML code saying “429: too many requests”

Theres a way to redirect a file on 404 requests that I am aware

app.get('*', (req, res) => [function])

But im unsure on 429 requests.

Yes, that’s correct. And @ItsYanko, if that’s the case, could I use that to display this page?

or you can send a file:

app.use((req, res) => {
  res.status(429).sendFile('./too-many-requests.html');
});

update: yay! my first solution!

4 Likes

Ah, thanks! That’s what I was looking for! Sadly I can’t test it because I’ll never get too many requests, but thanks! Will this work for all error codes?

I made something like this :slight_smile:
image

1 Like

You have a double “n” in many :wink:

1 Like

I got a error, app.stats is not a function

app.status is what @DerDer56 was referring to. I haven’t tried myself

Yes, you can do this for 404s as well!

status not stats :slight_smile:

Nice, however, when you try to go home it will just show that again :slight_smile: :smile:

Can you do it for others as well?

of course! 404, 403, 429, you name it!

3 Likes

even the 202 error code?

i’m not sure, but probably yes

yes, @DerDer56 made it!

1 Like