Source:
private <T, U> T completeOrForwardRequest(FutureCallback<T> cb, String path, String method, HttpHeaders headers, Object body, TypeReference<U> resultType, Translator<T, U> translator, Boolean forward) throws Throwable { try { return cb.get(REQUEST_TIMEOUT_MS, TimeUnit.MILLISECONDS); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof RequestTargetException) { if (forward == null || forward) { boolean recursiveForward = forward == null; RequestTargetException targetException = (RequestTargetException) cause; String forwardedUrl = targetException.forwardUrl(); if (forwardedUrl == null) { throw new ConnectRestException(Response.Status.CONFLICT.getStatusCode(), "Cannot complete request momentarily due no known leader URL, " + "perhaps because of a conflicting operation (e.g. worker rebalance)"); } String forwardUrl = UriBuilder.fromUri(forwardedUrl) .path(path) .queryParam("forward", recursiveForward) .build() .toString(); log.debug("Forwarding request {}", forwardUrl, method, body); return translator.translate(RestClient.httpRequest(forwardUrl, method, headers, body, resultType, config)); } else { throw new ConnectRestException(Response.Status.CONFLICT.getStatusCode(), "Cannot complete request because of a conflicting operation (e.g. worker rebalance)"); } } else if (cause instanceof RebalanceNeededException) { throw new ConnectRestException(Response.Status.CONFLICT.getStatusCode(), "Cannot complete request momentarily due to stale configuration (typically caused by a concurrent config change)"); } throw cause; } catch (TimeoutException e) { throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request timed out"); } catch (InterruptedException e) { throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request interrupted"); } }

Target:
private <T, U> T completeOrForwardRequest(FutureCallback<T> cb, String path, String method, HttpHeaders headers, Object body, TypeReference<U> resultType, Translator<T, U> translator, Boolean forward) throws Throwable { try { return cb.get(REQUEST_TIMEOUT_MS, TimeUnit.MILLISECONDS); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof RequestTargetException) { if (forward == null || forward) { boolean recursiveForward = forward == null; RequestTargetException targetException = (RequestTargetException) cause; String forwardedUrl = targetException.forwardUrl(); if (forwardedUrl == null) { throw new ConnectRestException(Response.Status.CONFLICT.getStatusCode(), "Cannot complete request momentarily due to no known leader URL, " + "likely because a rebalance was underway."); } String forwardUrl = UriBuilder.fromUri(forwardedUrl) .path(path) .queryParam("forward", recursiveForward) .build() .toString(); log.debug("Forwarding request {}", forwardUrl, method, body); return translator.translate(RestClient.httpRequest(forwardUrl, method, headers, body, resultType, config)); } else { throw new ConnectRestException(Response.Status.CONFLICT.getStatusCode(), "Cannot complete request because of a conflicting operation (e.g. worker rebalance)"); } } else if (cause instanceof RebalanceNeededException) { throw new ConnectRestException(Response.Status.CONFLICT.getStatusCode(), "Cannot complete request momentarily due to stale configuration (typically caused by a concurrent config change)"); } throw cause; } catch (TimeoutException e) { throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request timed out"); } catch (InterruptedException e) { throw new ConnectRestException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request interrupted"); } }