@Test void willThrowIfNothingElse() { CompoundInterceptor compound = new CompoundInterceptor( Arrays.asList() ); RuntimeException e = new RuntimeException(); UnirestException u = assertThrows(UnirestException.class, () -> compound.onFail(e, summary, config)); assertSame(e, u.getCause()); }
@Override public HttpResponse<?> onFail(Exception e, HttpRequestSummary request, Config config) throws UnirestException { return interceptors.stream() .map(i -> Optional.ofNullable(i.onFail(e, request, config))) .flatMap(Util::stream) .findFirst() .orElseThrow(() -> new UnirestException(e)); }
CompoundInterceptor implements Interceptor { @Override public HttpResponse<?> onFail(Exception e, HttpRequestSummary request, Config config) throws UnirestException { return interceptors.stream() .map(i -> Optional.ofNullable(i.onFail(e, request, config))) .flatMap(Util::stream) .findFirst() .orElseThrow(() -> new UnirestException(e)); } }
CompoundInterceptor implements Interceptor { @Override public HttpResponse<?> onFail(Exception e, HttpRequestSummary request, Config config) throws UnirestException { return interceptors.stream() .map(i -> Optional.ofNullable(i.onFail(e, request, config))) .flatMap(Util::stream) .findFirst() .orElseThrow(() -> new UnirestException(e)); } CompoundInterceptor();   CompoundInterceptor(List<Interceptor> interceptors); }
CompoundInterceptor implements Interceptor { @Override public HttpResponse<?> onFail(Exception e, HttpRequestSummary request, Config config) throws UnirestException { return interceptors.stream() .map(i -> Optional.ofNullable(i.onFail(e, request, config))) .flatMap(Util::stream) .findFirst() .orElseThrow(() -> new UnirestException(e)); } CompoundInterceptor();   CompoundInterceptor(List<Interceptor> interceptors); @Override void onRequest(HttpRequest<?> request, Config config); @Override void onResponse(HttpResponse<?> response, HttpRequestSummary request, Config config); @Override HttpResponse<?> onFail(Exception e, HttpRequestSummary request, Config config); }
CompoundInterceptor implements Interceptor { @Override public HttpResponse<?> onFail(Exception e, HttpRequestSummary request, Config config) throws UnirestException { return interceptors.stream() .map(i -> Optional.ofNullable(i.onFail(e, request, config))) .flatMap(Util::stream) .findFirst() .orElseThrow(() -> new UnirestException(e)); } CompoundInterceptor();   CompoundInterceptor(List<Interceptor> interceptors); @Override void onRequest(HttpRequest<?> request, Config config); @Override void onResponse(HttpResponse<?> response, HttpRequestSummary request, Config config); @Override HttpResponse<?> onFail(Exception e, HttpRequestSummary request, Config config);  }