Skip to content

Commit 8c63736

Browse files
committed
fixed edge not-found error handling
1 parent 2b72e06 commit 8c63736

File tree

3 files changed

+27
-38
lines changed

3 files changed

+27
-38
lines changed

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

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

2121
package com.arangodb.internal;
2222

23-
import com.arangodb.*;
23+
import com.arangodb.ArangoDBException;
24+
import com.arangodb.ArangoEdgeCollectionAsync;
25+
import com.arangodb.ArangoGraphAsync;
2426
import com.arangodb.entity.EdgeEntity;
2527
import com.arangodb.entity.EdgeUpdateEntity;
2628
import com.arangodb.model.*;
27-
import org.slf4j.Logger;
28-
import org.slf4j.LoggerFactory;
2929

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

3235
/**
3336
* @author Mark Vollmary
3437
*/
3538
public class ArangoEdgeCollectionAsyncImpl extends InternalArangoEdgeCollection implements ArangoEdgeCollectionAsync {
3639

37-
private static final Logger LOGGER = LoggerFactory.getLogger(ArangoEdgeCollectionAsyncImpl.class);
3840
private final ArangoGraphAsync graph;
3941

4042
protected ArangoEdgeCollectionAsyncImpl(final ArangoGraphAsyncImpl graph, final String name) {
@@ -70,27 +72,24 @@ public CompletableFuture<EdgeEntity> insertEdge(final Object value, final EdgeCr
7072

7173
@Override
7274
public <T> CompletableFuture<T> getEdge(final String key, final Class<T> type) {
73-
return executorAsync().execute(() -> getEdgeRequest(key, new GraphDocumentReadOptions()),
74-
getEdgeResponseDeserializer(type))
75-
.exceptionally(e -> {
76-
// FIXME
77-
if (LOGGER.isDebugEnabled()) {
78-
LOGGER.debug(e.getMessage(), e);
79-
}
80-
return null;
81-
});
82-
75+
return getEdge(key, type, null);
8376
}
8477

8578
@Override
8679
public <T> CompletableFuture<T> getEdge(final String key, final Class<T> type, final GraphDocumentReadOptions options) {
8780
return executorAsync().execute(() -> getEdgeRequest(key, options), getEdgeResponseDeserializer(type))
88-
.exceptionally(e -> {
89-
// FIXME
90-
if (LOGGER.isDebugEnabled()) {
91-
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+
}
9291
}
93-
return null;
92+
throw ArangoDBException.of(e);
9493
});
9594
}
9695

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@
2626
import com.arangodb.entity.EdgeEntity;
2727
import com.arangodb.entity.EdgeUpdateEntity;
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 ArangoEdgeCollectionImpl extends InternalArangoEdgeCollection implements ArangoEdgeCollection {
3636

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

4139
protected ArangoEdgeCollectionImpl(final ArangoGraphImpl graph, final String name) {
@@ -71,28 +69,21 @@ public EdgeEntity insertEdge(final Object value, final EdgeCreateOptions options
7169

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

8675
@Override
8776
public <T> T getEdge(final String key, final Class<T> type, final GraphDocumentReadOptions options) {
88-
// FIXME
8977
try {
9078
return executorSync().execute(getEdgeRequest(key, options), getEdgeResponseDeserializer(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

driver/src/test/java/com/arangodb/ArangoEdgeCollectionTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import com.arangodb.entity.*;
2424
import com.arangodb.model.*;
25-
import com.arangodb.util.TestUtils;
2625
import org.junit.jupiter.api.BeforeAll;
2726
import org.junit.jupiter.params.ParameterizedTest;
2827
import org.junit.jupiter.params.provider.Arguments;

0 commit comments

Comments
 (0)