Skip to content

Commit 2b72e06

Browse files
committed
fixed db not-found error handling
1 parent 206ade1 commit 2b72e06

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

core/src/main/java/com/arangodb/internal/ArangoDatabaseAsyncImpl.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@
3232

3333
import java.util.Collection;
3434
import java.util.Map;
35+
import java.util.Objects;
3536
import java.util.concurrent.CompletableFuture;
3637
import java.util.concurrent.CompletionException;
3738

39+
import static com.arangodb.internal.ArangoErrors.ERROR_ARANGO_DATABASE_NOT_FOUND;
40+
import static com.arangodb.internal.ArangoErrors.matches;
3841
import static com.arangodb.internal.serde.SerdeUtils.constructListType;
3942

4043
/**
@@ -67,21 +70,18 @@ public CompletableFuture<ArangoDBEngine> getEngine() {
6770

6871
@Override
6972
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+
});
8585
}
8686

8787
@Override
@@ -201,7 +201,7 @@ public <T> CompletableFuture<ArangoCursorAsync<T>> cursor(final String cursorId,
201201
final HostHandle hostHandle = new HostHandle();
202202
return executorAsync()
203203
.execute(() ->
204-
queryNextRequest(cursorId, new AqlQueryOptions(), nextBatchId),
204+
queryNextRequest(cursorId, new AqlQueryOptions(), nextBatchId),
205205
cursorEntityDeserializer(type),
206206
hostHandle)
207207
.thenApply(res -> new ArangoCursorAsyncImpl<>(this, res, type, hostHandle, nextBatchId != null));

core/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Collection;
3434
import java.util.Map;
3535

36+
import static com.arangodb.internal.ArangoErrors.*;
3637
import static com.arangodb.internal.serde.SerdeUtils.constructListType;
3738

3839
/**
@@ -69,7 +70,7 @@ public boolean exists() {
6970
getInfo();
7071
return true;
7172
} catch (final ArangoDBException e) {
72-
if (ArangoErrors.ERROR_ARANGO_DATABASE_NOT_FOUND.equals(e.getErrorNum())) {
73+
if (matches(e, 404, ERROR_ARANGO_DATABASE_NOT_FOUND)) {
7374
return false;
7475
}
7576
throw e;

0 commit comments

Comments
 (0)