### Question:
Requests { public static LiveHttpRequest doOnError(LiveHttpRequest request, Consumer<Throwable> action) { return request.newBuilder() .body(it -> it.doOnEnd(ifError(action))) .build(); } private  Requests(); static LiveHttpRequest doFinally(LiveHttpRequest request, Consumer<Optional<Throwable>> action); static LiveHttpResponse doFinally(LiveHttpResponse response, Consumer<Optional<Throwable>> action); static LiveHttpRequest doOnComplete(LiveHttpRequest request, Runnable action); static LiveHttpResponse doOnComplete(LiveHttpResponse response, Runnable action); static LiveHttpRequest doOnError(LiveHttpRequest request, Consumer<Throwable> action); static LiveHttpResponse doOnError(LiveHttpResponse response, Consumer<Throwable> action); static LiveHttpRequest doOnCancel(LiveHttpRequest request, Runnable action); static LiveHttpResponse doOnCancel(LiveHttpResponse response, Runnable action);  }### Answer:
@Test public void requestDoOnErrorDoesNotActivatesWhenSuccessfullyCompleted() { Requests.doOnError(request, (cause) -> completed.set(Optional.of(cause))) .consume(); publisher.next(new Buffer("content", UTF_8)); assertThat(completed.get(), is(nullValue())); publisher.complete(); assertThat(completed.get(), is(nullValue())); }
@Test public void responseDoOnErrorDoesNotActivatesWhenSuccessfullyCompleted() { Requests.doOnError(response, (cause) -> completed.set(Optional.of(cause))) .consume(); publisher.next(new Buffer("content", UTF_8)); assertThat(completed.get(), is(nullValue())); publisher.complete(); assertThat(completed.get(), is(nullValue())); }
@Test public void requestDoOnErrorActivatesWhenErrors() { RuntimeException cause = new RuntimeException("help!!"); Requests.doOnError(request, (it) -> completed.set(Optional.of(it))) .consume(); publisher.next(new Buffer("content", UTF_8)); assertThat(completed.get(), is(nullValue())); publisher.error(cause); assertThat(completed.get(), is(Optional.of(cause))); }
@Test public void responseDoOnErrorActivatesWhenErrors() { RuntimeException cause = new RuntimeException("help!!"); Requests.doOnError(response, (it) -> completed.set(Optional.of(it))) .consume(); publisher.next(new Buffer("content", UTF_8)); assertThat(completed.get(), is(nullValue())); publisher.error(cause); assertThat(completed.get(), is(Optional.of(cause))); }