private CompletableFuture call()

in src/main/java/com/spotify/github/v3/clients/GitHubClient.java [901:942]


  private CompletableFuture<Response> call(final Request request) {
    final Call call = client.newCall(request);

    final CompletableFuture<Response> future = new CompletableFuture<>();

    // avoid multiple redirects
    final AtomicBoolean redirected = new AtomicBoolean(false);

    call.enqueue(
        new Callback() {
          @Override
          public void onFailure(final Call call, final IOException e) {
            future.completeExceptionally(e);
          }

          @Override
          public void onResponse(final Call call, final Response response) {
            processPossibleRedirects(response, redirected)
                .handle(
                    (res, ex) -> {
                      if (Objects.nonNull(ex)) {
                        future.completeExceptionally(ex);
                      } else if (!res.isSuccessful()) {
                        try {
                          future.completeExceptionally(mapException(res, request));
                        } catch (final Throwable e) {
                          future.completeExceptionally(e);
                        } finally {
                          if (res.body() != null) {
                            res.body().close();
                          }
                        }
                      } else {
                        future.complete(res);
                      }
                      return res;
                    });
          }
        });
    tracer.span(request.url().toString(), request.method(), future);
    return future;
  }