use of com.hotels.styx.api.HttpResponseStatus in project styx by ExpediaGroup.
the class ExceptionStatusMapperTest method exceptionMayNotBeMappedToMultipleExceptions.
@Test
public void exceptionMayNotBeMappedToMultipleExceptions() {
ExceptionStatusMapper mapper = new ExceptionStatusMapper.Builder().add(BAD_GATEWAY, Exception1.class).add(GATEWAY_TIMEOUT, DoubleMappedException.class).build();
LoggingTestSupport support = new LoggingTestSupport(ExceptionStatusMapper.class);
Optional<HttpResponseStatus> status;
try {
status = mapper.statusFor(new DoubleMappedException());
} finally {
assertThat(support.lastMessage(), is(loggingEvent(ERROR, "Multiple matching statuses for throwable=" + quote(DoubleMappedException.class.getName()) + " statuses=\\[502 Bad Gateway, 504 Gateway Timeout\\]")));
}
assertThat(status, isAbsent());
}
use of com.hotels.styx.api.HttpResponseStatus in project styx by ExpediaGroup.
the class HttpPipelineHandler method exceptionToResponse.
private LiveHttpResponse exceptionToResponse(Throwable cause, LiveHttpRequest request, CharSequence originsHeaderName) {
HttpResponseStatus status = status(cause instanceof PluginException ? cause.getCause() : cause);
String message = status.code() >= 500 ? "Site temporarily unavailable." : status.description();
LiveHttpResponse.Transformer builder = responseEnhancer.enhance(response(status).body(new ByteStream(Flux.just(new Buffer(message, UTF_8)))).build().newBuilder(), request).header(CONTENT_LENGTH, message.getBytes(UTF_8).length).header(CONNECTION, "close");
if (originsHeaderName != null && originFromException(cause) != null) {
return builder.header(originsHeaderName, originFromException(cause)).build();
} else {
return builder.build();
}
}
Aggregations