|
32 | 32 |
|
33 | 33 | import java.util.Collection; |
34 | 34 | import java.util.Map; |
| 35 | +import java.util.Objects; |
35 | 36 | import java.util.concurrent.CompletableFuture; |
36 | 37 | import java.util.concurrent.CompletionException; |
37 | 38 |
|
| 39 | +import static com.arangodb.internal.ArangoErrors.ERROR_ARANGO_DATABASE_NOT_FOUND; |
| 40 | +import static com.arangodb.internal.ArangoErrors.matches; |
38 | 41 | import static com.arangodb.internal.serde.SerdeUtils.constructListType; |
39 | 42 |
|
40 | 43 | /** |
@@ -67,21 +70,18 @@ public CompletableFuture<ArangoDBEngine> getEngine() { |
67 | 70 |
|
68 | 71 | @Override |
69 | 72 | public CompletableFuture<Boolean> exists() { |
70 | | - return getInfo().handle((result, err) -> { |
71 | | - if (result != null) { |
72 | | - return true; |
73 | | - } |
74 | | - |
75 | | - Throwable e = err instanceof CompletionException ? err.getCause() : err; |
76 | | - if (e instanceof ArangoDBException) { |
77 | | - ArangoDBException aEx = (ArangoDBException) e; |
78 | | - if (ArangoErrors.ERROR_ARANGO_DATABASE_NOT_FOUND.equals(aEx.getErrorNum())) { |
79 | | - return false; |
80 | | - } |
81 | | - } |
82 | | - |
83 | | - throw ArangoDBException.of(e); |
84 | | - }); |
| 73 | + return getInfo() |
| 74 | + .thenApply(Objects::nonNull) |
| 75 | + .exceptionally(err -> { |
| 76 | + Throwable e = err instanceof CompletionException ? err.getCause() : err; |
| 77 | + if (e instanceof ArangoDBException) { |
| 78 | + ArangoDBException aEx = (ArangoDBException) e; |
| 79 | + if (matches(aEx, 404, ERROR_ARANGO_DATABASE_NOT_FOUND)) { |
| 80 | + return false; |
| 81 | + } |
| 82 | + } |
| 83 | + throw ArangoDBException.of(e); |
| 84 | + }); |
85 | 85 | } |
86 | 86 |
|
87 | 87 | @Override |
@@ -201,7 +201,7 @@ public <T> CompletableFuture<ArangoCursorAsync<T>> cursor(final String cursorId, |
201 | 201 | final HostHandle hostHandle = new HostHandle(); |
202 | 202 | return executorAsync() |
203 | 203 | .execute(() -> |
204 | | - queryNextRequest(cursorId, new AqlQueryOptions(), nextBatchId), |
| 204 | + queryNextRequest(cursorId, new AqlQueryOptions(), nextBatchId), |
205 | 205 | cursorEntityDeserializer(type), |
206 | 206 | hostHandle) |
207 | 207 | .thenApply(res -> new ArangoCursorAsyncImpl<>(this, res, type, hostHandle, nextBatchId != null)); |
|
0 commit comments