Package com.linecorp.armeria.server
Class HttpStatusException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.linecorp.armeria.server.HttpStatusException
- All Implemented Interfaces:
Serializable
A
RuntimeException
that is raised to send a simplistic HTTP response with minimal content
by a Service
. It is a general exception raised by a failed request or a reset stream.
Note that a raised HttpStatusException
may not be applied to the next decorators if the
HttpStatusException
is not recovered before passed to the next decorator chain.
For this reason, the thrown HttpStatusException
should be converted into a normal
HttpResponse
using HttpResponse.recover(Function)
or
httpStatus()
.
For example:
// Catch an HttpStatusException and convert into an HttpResponse
try {
throwableService();
} catch (HttpStatusException ex) {
return HttpResponse.of(ex.httpStatus());
}
// Recover the HttpStatusException using HttpResponse.recover()
HttpResponse response = ...;
response.recover(ex -> {
if (ex instanceof HttpStatusException) {
return HttpResponse.of(((HttpStatusException) ex).httpStatus());
} else {
return HttpResponse.ofFailure(ex);
}
})
An unhandled HttpStatusException
will be recovered by the default ServerErrorHandler
in the end. If you want to mutate the HttpResponse
made of the HttpStatusException
, you can
add a custom ServerErrorHandler
.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns theHttpStatus
which would be sent back to the client who sent the corresponding request.static HttpStatusException
of
(int statusCode) Returns a newHttpStatusException
instance with the specified HTTP status code.static HttpStatusException
Returns a newHttpStatusException
instance with the specified HTTP status code andcause
.static HttpStatusException
of
(HttpStatus status) Returns a newHttpStatusException
instance with the specifiedHttpStatus
.static HttpStatusException
of
(HttpStatus status, Throwable cause) Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Method Details
-
of
Returns a newHttpStatusException
instance with the specified HTTP status code. -
of
Returns a newHttpStatusException
instance with the specified HTTP status code andcause
. -
of
Returns a newHttpStatusException
instance with the specifiedHttpStatus
. -
of
-
httpStatus
Returns theHttpStatus
which would be sent back to the client who sent the corresponding request.
-