@Target(value={TYPE,METHOD})
@Retention(value=RUNTIME)
@Documented
public @interface ResponseStatus
code()
and
reason()
that should be returned.
The status code is applied to the HTTP response when the handler method is invoked, or whenever said exception is thrown.
ResponseStatusExceptionResolver
Modifier and Type | Optional Element and Description |
---|---|
HttpStatus |
code
The status code to use for the response.
|
java.lang.String |
reason
The reason to be used for the response.
|
HttpStatus |
value
Alias for
code() . |
@AliasFor(attribute="code") public abstract HttpStatus value
code()
.@AliasFor(attribute="value") public abstract HttpStatus code
Default is HttpStatus.INTERNAL_SERVER_ERROR
, which should
typically be changed to something more appropriate.
javax.servlet.http.HttpServletResponse#setStatus(int)
public abstract java.lang.String reason
Note: due to the use of
HttpServletResponse.sendError(int, String)
, the response will be
considered complete and should not be written to any further. Furthermore
servlet container will typically write an HTML error page therefore making
the use of a reason unsuitable for REST APIs. For such cases prefer
sending error details in the body of the response.
javax.servlet.http.HttpServletResponse#sendError(int, String)