0

I am looking for a way to have a custom status and error code that is outside the usual http range of error code. Something like this:

return javax.ws.rs.core.Response.status(8001).entity("Error replacing document").build();

I get: java.lang.IllegalArgumentException: Illegal status value: 8001

Any pointers on how to accomplish this?

Sathish Kumar
  • 313
  • 2
  • 15

1 Answers1

0

Allowed status codes in Response.status() are 100..599:

public ResponseBuilder status(int s) {
    if (s < 100 || s > 599) {
        throw new IllegalArgumentException("Illegal status value : " + s);
    }
    ...

The list of defined status codes in HTTP: https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html. Every status code has its meaning and use.

I guess this is a duplicate for Can we create custom HTTP Status codes?

Community
  • 1
  • 1
radoh
  • 4,554
  • 5
  • 30
  • 45
  • In tomcat,any error code works. apache cxf running in karaf container is facing this issue! – Sathish Kumar Apr 14 '17 at 08:54
  • 1
    @SathishKumar The point is, codes outside of the `100..599` are not in HTTP spec, many consider them illegal and it's against good practice. – radoh Apr 14 '17 at 09:54