Sathish Kumar
Sathish Kumar

Reputation: 321

Returning custom status and code on java rest api

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?

Upvotes: 0

Views: 1875

Answers (1)

radoh
radoh

Reputation: 4809

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?

Upvotes: 0

Related Questions