Skip to content

Commit 206ade1

Browse files
committed
fixed not-found error handling in ArangoCollectionAsyncImpl
1 parent 1fea646 commit 206ade1

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

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

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.concurrent.CompletableFuture;
3333
import java.util.concurrent.CompletionException;
3434

35+
import static com.arangodb.internal.ArangoErrors.*;
3536
import static com.arangodb.internal.serde.SerdeUtils.constructParametricType;
3637

3738
/**
@@ -136,7 +137,19 @@ public <T> CompletableFuture<T> getDocument(final String key, final Class<T> typ
136137
@Override
137138
public <T> CompletableFuture<T> getDocument(final String key, final Class<T> type, final DocumentReadOptions options) {
138139
return executorAsync().execute(() -> getDocumentRequest(key, options), getDocumentResponseDeserializer(type))
139-
.exceptionally(this::catchGetDocumentExceptions);
140+
.exceptionally(err -> {
141+
Throwable e = err instanceof CompletionException ? err.getCause() : err;
142+
if (e instanceof ArangoDBException) {
143+
ArangoDBException aEx = (ArangoDBException) e;
144+
if (matches(aEx, 304)
145+
|| matches(aEx, 404, ERROR_ARANGO_DOCUMENT_NOT_FOUND)
146+
|| matches(aEx, 412, ERROR_ARANGO_CONFLICT)
147+
) {
148+
return null;
149+
}
150+
}
151+
throw ArangoDBException.of(e);
152+
});
140153
}
141154

142155
@Override
@@ -313,26 +326,19 @@ public CompletableFuture<Boolean> documentExists(final String key) {
313326
public CompletableFuture<Boolean> documentExists(final String key, final DocumentExistsOptions options) {
314327
return executorAsync().execute(() -> documentExistsRequest(key, options), Void.class)
315328
.thenApply(it -> true)
316-
.exceptionally(this::catchGetDocumentExceptions)
317-
.thenApply(Objects::nonNull);
318-
}
319-
320-
<T> T catchGetDocumentExceptions(Throwable err) {
321-
Throwable e = err instanceof CompletionException ? err.getCause() : err;
322-
if (e instanceof ArangoDBException) {
323-
ArangoDBException arangoDBException = (ArangoDBException) e;
324-
325-
// handle Response: 404, Error: 1655 - transaction not found
326-
if (arangoDBException.getErrorNum() != null && arangoDBException.getErrorNum() == 1655) {
327-
throw (ArangoDBException) e;
328-
}
329-
330-
if ((arangoDBException.getResponseCode() != null && (arangoDBException.getResponseCode() == 404 || arangoDBException.getResponseCode() == 304
331-
|| arangoDBException.getResponseCode() == 412))) {
332-
return null;
333-
}
334-
}
335-
throw ArangoDBException.of(e);
329+
.exceptionally(err -> {
330+
Throwable e = err instanceof CompletionException ? err.getCause() : err;
331+
if (e instanceof ArangoDBException) {
332+
ArangoDBException aEx = (ArangoDBException) e;
333+
if (matches(aEx, 304)
334+
|| matches(aEx, 404)
335+
|| matches(aEx, 412)
336+
) {
337+
return false;
338+
}
339+
}
340+
throw ArangoDBException.of(e);
341+
});
336342
}
337343

338344
@Override
@@ -399,7 +405,7 @@ public CompletableFuture<Boolean> exists() {
399405
Throwable e = err instanceof CompletionException ? err.getCause() : err;
400406
if (e instanceof ArangoDBException) {
401407
ArangoDBException aEx = (ArangoDBException) e;
402-
if (ArangoErrors.ERROR_ARANGO_DATA_SOURCE_NOT_FOUND.equals(aEx.getErrorNum())) {
408+
if (matches(aEx, 404, ERROR_ARANGO_DATA_SOURCE_NOT_FOUND)) {
403409
return false;
404410
}
405411
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,10 @@ public boolean exists() {
394394
getInfo();
395395
return true;
396396
} catch (final ArangoDBException e) {
397-
if (!matches(e, 404, ERROR_ARANGO_DATA_SOURCE_NOT_FOUND)) {
398-
throw e;
397+
if (matches(e, 404, ERROR_ARANGO_DATA_SOURCE_NOT_FOUND)) {
398+
return false;
399399
}
400-
return false;
400+
throw e;
401401
}
402402
}
403403

0 commit comments

Comments
 (0)