Reputation: 1157
Feel free to close if this doesn't really belong on StackOverflow.
javax.servlet.http.HttpServletResponse
has a bunch of useful constants (such as SC_BAD_REQUEST
, SC_NOT_FOUND
etc) but for some reason there isn't one for HTTP 429. Is there another place to find such a constant? Is there a reason it was omitted from the class?
Upvotes: 8
Views: 2009
Reputation: 7381
I don't know why they omitted it, but you can send an error with the sendError(int i, String s)
method of HttpServletResponse
. This takes an int as the first argument, so you can simply use 429
as the parameter. The second argument takes the error message. For this you could use the phrase "Too many requests".
If you are using the Spring framework then you can also use HttpStatus.TOO_MANY_REQUESTS.value()
if you really want to use a constant.
Upvotes: 2