Package com.linecorp.armeria.server
Class HttpResponseException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.linecorp.armeria.server.HttpResponseException
- All Implemented Interfaces:
Serializable
A
RuntimeException
that is raised to send an HTTP response with the content specified
by a user. This class holds an HttpResponse
which would be sent back to the client who
sent the corresponding request.
Note that a raised HttpResponseException
may not be applied to the next decorators if the
HttpResponseException
is not recovered before being passed to the next decorator chain.
For this reason, the thrown HttpResponseException
should be converted into a normal
HttpResponse
using HttpResponse.recover(Function)
or
httpResponse()
.
For example:
// Catch the HttpResponseException and convert into an HttpResponse
try {
throwableService();
} catch (HttpResponseException ex) {
return ex.httpResponse();
}
// Recover the HttpResponseException using HttpResponse.recover()
HttpResponse response = ...;
response.recover(ex -> {
if (ex instanceof HttpResponseException) {
return ((HttpResponseException) ex).httpResponse();
} else {
return HttpResponse.ofFailure(ex);
}
})
An unhandled HttpResponseException
is recovered by the default ServerErrorHandler
in the
end. If you want to mutate the HttpResponse
in the HttpResponseException
, you can add a
custom ServerErrorHandler
.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns theHttpResponse
which would be sent back to the client who sent the corresponding request.static HttpResponseException
of
(int statusCode) Deprecated.static HttpResponseException
of
(AggregatedHttpResponse aggregatedResponse) Returns a newHttpResponseException
instance with the specifiedAggregatedHttpResponse
.static HttpResponseException
of
(AggregatedHttpResponse aggregatedResponse, @Nullable Throwable cause) Returns a newHttpResponseException
instance with the specifiedAggregatedHttpResponse
andThrowable
.static HttpResponseException
of
(HttpResponse httpResponse) Returns a newHttpResponseException
instance with the specifiedHttpResponse
.static HttpResponseException
of
(HttpResponse httpResponse, @Nullable Throwable cause) static HttpResponseException
of
(HttpStatus httpStatus) Deprecated.UseHttpStatusException.of(HttpStatus)
instead.Methods inherited from class java.lang.Throwable
addSuppressed, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Method Details
-
of
Deprecated.UseHttpStatusException.of(int)
instead.Returns a newHttpResponseException
instance with the specified HTTP status code. -
of
Deprecated.UseHttpStatusException.of(HttpStatus)
instead.Returns a newHttpResponseException
instance with the specifiedHttpStatus
. -
of
Returns a newHttpResponseException
instance with the specifiedAggregatedHttpResponse
. -
of
public static HttpResponseException of(AggregatedHttpResponse aggregatedResponse, @Nullable @Nullable Throwable cause) Returns a newHttpResponseException
instance with the specifiedAggregatedHttpResponse
andThrowable
. -
of
Returns a newHttpResponseException
instance with the specifiedHttpResponse
. -
of
public static HttpResponseException of(HttpResponse httpResponse, @Nullable @Nullable Throwable cause) -
httpResponse
Returns theHttpResponse
which would be sent back to the client who sent the corresponding request. -
fillInStackTrace
- Overrides:
fillInStackTrace
in classThrowable
-
HttpStatusException.of(int)
instead.