@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: 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)); }
private static HttpResponseStatus status(Throwable exception) { return EXCEPTION_STATUSES.statusFor(exception) .orElseGet(() -> { if (exception instanceof DecoderException) { Throwable cause = exception.getCause(); if (cause instanceof BadRequestException) { if (cause.getCause() instanceof TooLongFrameException) { return REQUEST_ENTITY_TOO_LARGE; } return BAD_REQUEST; } } else if (exception instanceof TransportLostException) { return BAD_GATEWAY; } return INTERNAL_SERVER_ERROR; }); }
HttpPipelineHandler extends SimpleChannelInboundHandler<LiveHttpRequest> { private static HttpResponseStatus status(Throwable exception) { return EXCEPTION_STATUSES.statusFor(exception) .orElseGet(() -> { if (exception instanceof DecoderException) { Throwable cause = exception.getCause(); if (cause instanceof BadRequestException) { if (cause.getCause() instanceof TooLongFrameException) { return REQUEST_ENTITY_TOO_LARGE; } return BAD_REQUEST; } } else if (exception instanceof TransportLostException) { return BAD_GATEWAY; } return INTERNAL_SERVER_ERROR; }); } }
HttpPipelineHandler extends SimpleChannelInboundHandler<LiveHttpRequest> { private static HttpResponseStatus status(Throwable exception) { return EXCEPTION_STATUSES.statusFor(exception) .orElseGet(() -> { if (exception instanceof DecoderException) { Throwable cause = exception.getCause(); if (cause instanceof BadRequestException) { if (cause.getCause() instanceof TooLongFrameException) { return REQUEST_ENTITY_TOO_LARGE; } return BAD_REQUEST; } } else if (exception instanceof TransportLostException) { return BAD_GATEWAY; } return INTERNAL_SERVER_ERROR; }); } private  HttpPipelineHandler(Builder builder, RequestTracker tracker); }
HttpPipelineHandler extends SimpleChannelInboundHandler<LiveHttpRequest> { private static HttpResponseStatus status(Throwable exception) { return EXCEPTION_STATUSES.statusFor(exception) .orElseGet(() -> { if (exception instanceof DecoderException) { Throwable cause = exception.getCause(); if (cause instanceof BadRequestException) { if (cause.getCause() instanceof TooLongFrameException) { return REQUEST_ENTITY_TOO_LARGE; } return BAD_REQUEST; } } else if (exception instanceof TransportLostException) { return BAD_GATEWAY; } return INTERNAL_SERVER_ERROR; }); } private  HttpPipelineHandler(Builder builder, RequestTracker tracker); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); }
HttpPipelineHandler extends SimpleChannelInboundHandler<LiveHttpRequest> { private static HttpResponseStatus status(Throwable exception) { return EXCEPTION_STATUSES.statusFor(exception) .orElseGet(() -> { if (exception instanceof DecoderException) { Throwable cause = exception.getCause(); if (cause instanceof BadRequestException) { if (cause.getCause() instanceof TooLongFrameException) { return REQUEST_ENTITY_TOO_LARGE; } return BAD_REQUEST; } } else if (exception instanceof TransportLostException) { return BAD_GATEWAY; } return INTERNAL_SERVER_ERROR; }); } private  HttpPipelineHandler(Builder builder, RequestTracker tracker); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause);  }