use of com.canoo.platform.core.http.BadResponseException in project dolphin-platform by canoo.
the class HttpCallExecutorImpl method execute.
@Override
public CompletableFuture<HttpResponse<R>> execute() {
final CompletableFuture<HttpResponse<R>> completableFuture = new CompletableFuture<>();
executor.submit(() -> {
try {
final HttpResponse<R> result = provider.get();
final int statusCode = result.getStatusCode();
if (statusCode >= 300) {
final HttpException e = new BadResponseException(result, "Bad Response: " + statusCode);
if (errorHandler != null) {
uiExecutor.execute(() -> errorHandler.accept(e));
}
completableFuture.completeExceptionally(e);
} else {
if (onDone != null) {
uiExecutor.execute(() -> onDone.accept(result));
}
completableFuture.complete(result);
}
} catch (final HttpException e) {
if (errorHandler != null) {
uiExecutor.execute(() -> errorHandler.accept(e));
}
completableFuture.completeExceptionally(e);
}
});
return completableFuture;
}
Aggregations