@Test
public void doOnError() {

	disposableServer =
			HttpServer.create()
			          .port(0)
			          .handle((req, resp) -> {
			              if (req.requestHeaders().contains("during")) {
			                  return resp.sendString(Flux.just("test").hide())
			                             .then(Mono.error(new RuntimeException("test")));
			              }
			              throw new RuntimeException("test");
			          })
			          .bindNow();
	AtomicReference<String> requestError1 = new AtomicReference<>();
	AtomicReference<String> responseError1 = new AtomicReference<>();
	Mono<String> content =
			createHttpClientForContextWithPort()
			        .headers(h -> h.add("before", "test"))
			        .doOnRequestError((req, err) ->
			            requestError1.set(req.currentContextView().getOrDefault("test", "empty")))
			        .doOnResponseError((res, err) ->
			            responseError1.set(res.currentContextView().getOrDefault("test", "empty")))
			        .mapConnect((c) -> c.contextWrite(Context.of("test", "success")))
			        .get()
			        .uri("/")
			        .responseContent()
			        .aggregate()
			        .asString();
	StepVerifier.create(content)
	            .verifyError(PrematureCloseException.class);
	assertThat(requestError1.get()).isEqualTo("success");
	assertThat(responseError1.get()).isNull();
	AtomicReference<String> requestError2 = new AtomicReference<>();
	AtomicReference<String> responseError2 = new AtomicReference<>();
	content =
			createHttpClientForContextWithPort()
			        .headers(h -> h.add("during", "test"))
			        .doOnError((req, err) ->
			            requestError2.set(req.currentContextView().getOrDefault("test", "empty"))
			            ,(res, err) ->
			            responseError2.set(res.currentContextView().getOrDefault("test", "empty")))
			        .mapConnect((c) -> c.contextWrite(Context.of("test", "success")))
			        .get()
			        .uri("/")
			        .responseContent()
			        .aggregate()
			        .asString();
	StepVerifier.create(content)
	            .verifyError(PrematureCloseException.class);
	assertThat(requestError2.get()).isNull();
	assertThat(responseError2.get()).isEqualTo("success");
}