Skip to content

Commit 1fea646

Browse files
committed
fixed not-found error handling in ArangoCollectionImpl
1 parent 9aff4de commit 1fea646

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

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

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626
import com.arangodb.entity.*;
2727
import com.arangodb.model.*;
2828
import com.arangodb.util.RawData;
29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
3129

3230
import java.util.Collection;
3331

32+
import static com.arangodb.internal.ArangoErrors.*;
3433
import static com.arangodb.internal.serde.SerdeUtils.constructParametricType;
3534

3635
/**
@@ -39,8 +38,6 @@
3938
*/
4039
public class ArangoCollectionImpl extends InternalArangoCollection implements ArangoCollection {
4140

42-
private static final Logger LOGGER = LoggerFactory.getLogger(ArangoCollectionImpl.class);
43-
4441
private final ArangoDatabase db;
4542

4643
protected ArangoCollectionImpl(final ArangoDatabaseImpl db, final String name) {
@@ -139,17 +136,10 @@ public <T> T getDocument(final String key, final Class<T> type, final DocumentRe
139136
try {
140137
return executorSync().execute(getDocumentRequest(key, options), getDocumentResponseDeserializer(type));
141138
} catch (final ArangoDBException e) {
142-
if (LOGGER.isDebugEnabled()) {
143-
LOGGER.debug(e.getMessage(), e);
144-
}
145-
146-
// handle Response: 404, Error: 1655 - transaction not found
147-
if (e.getErrorNum() != null && e.getErrorNum() == 1655) {
148-
throw e;
149-
}
150-
151-
if ((e.getResponseCode() != null && (e.getResponseCode() == 404 || e.getResponseCode() == 304
152-
|| e.getResponseCode() == 412))) {
139+
if (matches(e, 304)
140+
|| matches(e, 404, ERROR_ARANGO_DOCUMENT_NOT_FOUND)
141+
|| matches(e, 412, ERROR_ARANGO_CONFLICT)
142+
) {
153143
return null;
154144
}
155145
throw e;
@@ -332,14 +322,10 @@ public Boolean documentExists(final String key, final DocumentExistsOptions opti
332322
executorSync().execute(documentExistsRequest(key, options), Void.class);
333323
return true;
334324
} catch (final ArangoDBException e) {
335-
336-
// handle Response: 404, Error: 1655 - transaction not found
337-
if (e.getErrorNum() != null && e.getErrorNum() == 1655) {
338-
throw e;
339-
}
340-
341-
if ((e.getResponseCode() != null &&
342-
(e.getResponseCode() == 404 || e.getResponseCode() == 304 || e.getResponseCode() == 412))) {
325+
if (matches(e, 304)
326+
|| matches(e, 404)
327+
|| matches(e, 412)
328+
) {
343329
return false;
344330
}
345331
throw e;
@@ -408,10 +394,10 @@ public boolean exists() {
408394
getInfo();
409395
return true;
410396
} catch (final ArangoDBException e) {
411-
if (ArangoErrors.ERROR_ARANGO_DATA_SOURCE_NOT_FOUND.equals(e.getErrorNum())) {
412-
return false;
397+
if (!matches(e, 404, ERROR_ARANGO_DATA_SOURCE_NOT_FOUND)) {
398+
throw e;
413399
}
414-
throw e;
400+
return false;
415401
}
416402
}
417403

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,29 @@
2020

2121
package com.arangodb.internal;
2222

23+
import com.arangodb.ArangoDBException;
24+
2325
/**
2426
* @author Mark Vollmary
2527
*/
2628
public final class ArangoErrors {
2729

30+
public static final Integer ERROR_ARANGO_CONFLICT = 1200;
31+
public static final Integer ERROR_ARANGO_DOCUMENT_NOT_FOUND = 1202;
2832
public static final Integer ERROR_ARANGO_DATA_SOURCE_NOT_FOUND = 1203;
2933
public static final Integer ERROR_ARANGO_DATABASE_NOT_FOUND = 1228;
3034
public static final Integer ERROR_GRAPH_NOT_FOUND = 1924;
3135
public static final Integer QUEUE_TIME_VIOLATED = 21004;
3236

37+
public static boolean matches(ArangoDBException e, int responseCode, int errorNum) {
38+
return matches(e, responseCode)
39+
&& e.getErrorNum() != null && e.getErrorNum() == errorNum;
40+
}
41+
42+
public static boolean matches(ArangoDBException e, int responseCode) {
43+
return e.getResponseCode() != null && e.getResponseCode() == responseCode;
44+
}
45+
3346
private ArangoErrors() {
3447
super();
3548
}

0 commit comments

Comments
 (0)