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?

0

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

In tomcat,any error code works. apache cxf running in karaf container is facing this issue!
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.