use of com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR in project styx by ExpediaGroup.
the class UrlPatternRouter method handle.
@Override
public Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context) {
for (RouteDescriptor route : alternatives) {
if (request.method().equals(route.method())) {
Matcher match = route.uriPattern().matcher(request.path());
LOGGER.debug("Request path '{}' matching against route pattern '{}' matches: {}", new Object[] { request.path(), route.uriPattern(), match.matches() });
if (match.matches()) {
Map<String, String> placeholders = route.placeholderNames().stream().collect(toMap(name -> name, match::group));
context.add(PLACEHOLDERS_KEY, placeholders);
try {
return route.handler().handle(request, context);
} catch (Exception cause) {
LOGGER.error("ERROR: {} {}", new Object[] { request.method(), request.path(), cause });
return Eventual.of(response(INTERNAL_SERVER_ERROR).build());
}
}
}
}
return Eventual.of(response(NOT_FOUND).build());
}
use of com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method mapsUnrecoverableInternalErrorsToInternalServerError500ResponseCode.
@Test
public void mapsUnrecoverableInternalErrorsToInternalServerError500ResponseCode() {
HttpHandler handler = (request, context) -> {
throw new RuntimeException("Forced exception for testing");
};
EmbeddedChannel channel = buildEmbeddedChannel(handlerWithMocks(handler));
channel.writeInbound(httpRequestAsBuf(GET, "http://foo.com/"));
DefaultHttpResponse response = (DefaultHttpResponse) channel.readOutbound();
assertThat(response.status(), is(io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR));
verify(responseEnhancer).enhance(any(LiveHttpResponse.Transformer.class), any(LiveHttpRequest.class));
verify(errorListener, only()).proxyErrorOccurred(any(LiveHttpRequest.class), any(InetSocketAddress.class), eq(INTERNAL_SERVER_ERROR), any(RuntimeException.class));
}
use of com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR in project styx by ExpediaGroup.
the class InstrumentedPluginTest method metricIsNotRecordedWhenErrorStatusIsReturnedByChain.
@Test
public void metricIsNotRecordedWhenErrorStatusIsReturnedByChain() {
Chain chain = request -> aResponse(INTERNAL_SERVER_ERROR);
String pluginName = "doNotRecordMe";
InstrumentedPlugin plugin = instrumentedPlugin(pluginName, PASS_THROUGH);
LiveHttpResponse response = Mono.from(plugin.intercept(someRequest, chain)).block();
assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
assertThat(getStatusCount(pluginName, "500"), is(0.0));
assertThat(getErrorCount(pluginName), is(0.0));
}
use of com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR in project styx by ExpediaGroup.
the class InstrumentedPluginTest method metricIsRecordedWhenResponseIsMappedToErrorStatus.
@Test
public void metricIsRecordedWhenResponseIsMappedToErrorStatus() {
Chain chain = request -> aResponse(OK);
String pluginName = "replaceStatus1";
InstrumentedPlugin plugin = instrumentedPlugin(pluginName, (request, aChain) -> aChain.proceed(request).map(response -> responseWithNewStatusCode(response, INTERNAL_SERVER_ERROR)));
LiveHttpResponse response = Mono.from(plugin.intercept(someRequest, chain)).block();
assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
assertThat(getStatusCount(pluginName, "500"), is(1.0));
assertThat(getErrorCount(pluginName), is(1.0));
}
Aggregations