Skip to content

Commit b1f4451

Browse files
committed
fixed vertex not-found error handling
1 parent 8c63736 commit b1f4451

File tree

2 files changed

+25
-37
lines changed

2 files changed

+25
-37
lines changed

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@
2020

2121
package com.arangodb.internal;
2222

23+
import com.arangodb.ArangoDBException;
2324
import com.arangodb.ArangoGraphAsync;
2425
import com.arangodb.ArangoVertexCollectionAsync;
2526
import com.arangodb.entity.VertexEntity;
2627
import com.arangodb.entity.VertexUpdateEntity;
2728
import com.arangodb.model.*;
28-
import org.slf4j.Logger;
29-
import org.slf4j.LoggerFactory;
3029

3130
import java.util.concurrent.CompletableFuture;
31+
import java.util.concurrent.CompletionException;
32+
33+
import static com.arangodb.internal.ArangoErrors.*;
3234

3335
/**
3436
* @author Mark Vollmary
3537
*/
3638
public class ArangoVertexCollectionAsyncImpl extends InternalArangoVertexCollection implements ArangoVertexCollectionAsync {
3739

38-
private static final Logger LOGGER = LoggerFactory.getLogger(ArangoVertexCollectionAsyncImpl.class);
39-
4040
private final ArangoGraphAsync graph;
4141

4242
protected ArangoVertexCollectionAsyncImpl(final ArangoGraphAsyncImpl graph, final String name) {
@@ -72,27 +72,24 @@ public CompletableFuture<VertexEntity> insertVertex(final Object value, final Ve
7272

7373
@Override
7474
public <T> CompletableFuture<T> getVertex(final String key, final Class<T> type) {
75-
return executorAsync().execute(() -> getVertexRequest(key, new GraphDocumentReadOptions()),
76-
getVertexResponseDeserializer(type))
77-
.exceptionally(e -> {
78-
// FIXME
79-
if (LOGGER.isDebugEnabled()) {
80-
LOGGER.debug(e.getMessage(), e);
81-
}
82-
return null;
83-
});
84-
75+
return getVertex(key, type, null);
8576
}
8677

8778
@Override
8879
public <T> CompletableFuture<T> getVertex(final String key, final Class<T> type, final GraphDocumentReadOptions options) {
8980
return executorAsync().execute(() -> getVertexRequest(key, options), getVertexResponseDeserializer(type))
90-
.exceptionally(e -> {
91-
// FIXME
92-
if (LOGGER.isDebugEnabled()) {
93-
LOGGER.debug(e.getMessage(), e);
81+
.exceptionally(err -> {
82+
Throwable e = err instanceof CompletionException ? err.getCause() : err;
83+
if (e instanceof ArangoDBException) {
84+
ArangoDBException aEx = (ArangoDBException) e;
85+
if (matches(aEx, 304)
86+
|| matches(aEx, 404, ERROR_ARANGO_DOCUMENT_NOT_FOUND)
87+
|| matches(aEx, 412, ERROR_ARANGO_CONFLICT)
88+
) {
89+
return null;
90+
}
9491
}
95-
return null;
92+
throw ArangoDBException.of(e);
9693
});
9794
}
9895

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@
2626
import com.arangodb.entity.VertexEntity;
2727
import com.arangodb.entity.VertexUpdateEntity;
2828
import com.arangodb.model.*;
29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
29+
30+
import static com.arangodb.internal.ArangoErrors.*;
3131

3232
/**
3333
* @author Mark Vollmary
3434
*/
3535
public class ArangoVertexCollectionImpl extends InternalArangoVertexCollection implements ArangoVertexCollection {
3636

37-
private static final Logger LOGGER = LoggerFactory.getLogger(ArangoVertexCollectionImpl.class);
38-
3937
private final ArangoGraph graph;
4038

4139
protected ArangoVertexCollectionImpl(final ArangoGraphImpl graph, final String name) {
@@ -71,28 +69,21 @@ public VertexEntity insertVertex(final Object value, final VertexCreateOptions o
7169

7270
@Override
7371
public <T> T getVertex(final String key, final Class<T> type) {
74-
// FIXME
75-
try {
76-
return executorSync().execute(getVertexRequest(key, new GraphDocumentReadOptions()),
77-
getVertexResponseDeserializer(type));
78-
} catch (final ArangoDBException e) {
79-
if (LOGGER.isDebugEnabled()) {
80-
LOGGER.debug(e.getMessage(), e);
81-
}
82-
return null;
83-
}
72+
return getVertex(key, type, null);
8473
}
8574

8675
@Override
8776
public <T> T getVertex(final String key, final Class<T> type, final GraphDocumentReadOptions options) {
88-
// FIXME
8977
try {
9078
return executorSync().execute(getVertexRequest(key, options), getVertexResponseDeserializer(type));
9179
} catch (final ArangoDBException e) {
92-
if (LOGGER.isDebugEnabled()) {
93-
LOGGER.debug(e.getMessage(), e);
80+
if (matches(e, 304)
81+
|| matches(e, 404, ERROR_ARANGO_DOCUMENT_NOT_FOUND)
82+
|| matches(e, 412, ERROR_ARANGO_CONFLICT)
83+
) {
84+
return null;
9485
}
95-
return null;
86+
throw e;
9687
}
9788
}
9889

0 commit comments

Comments
 (0)