|
32 | 32 | import java.util.concurrent.CompletableFuture;
|
33 | 33 | import java.util.concurrent.CompletionException;
|
34 | 34 |
|
| 35 | +import static com.arangodb.internal.ArangoErrors.*; |
35 | 36 | import static com.arangodb.internal.serde.SerdeUtils.constructParametricType;
|
36 | 37 |
|
37 | 38 | /**
|
@@ -136,7 +137,19 @@ public <T> CompletableFuture<T> getDocument(final String key, final Class<T> typ
|
136 | 137 | @Override
|
137 | 138 | public <T> CompletableFuture<T> getDocument(final String key, final Class<T> type, final DocumentReadOptions options) {
|
138 | 139 | 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 | + }); |
140 | 153 | }
|
141 | 154 |
|
142 | 155 | @Override
|
@@ -313,26 +326,19 @@ public CompletableFuture<Boolean> documentExists(final String key) {
|
313 | 326 | public CompletableFuture<Boolean> documentExists(final String key, final DocumentExistsOptions options) {
|
314 | 327 | return executorAsync().execute(() -> documentExistsRequest(key, options), Void.class)
|
315 | 328 | .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 | + }); |
336 | 342 | }
|
337 | 343 |
|
338 | 344 | @Override
|
@@ -399,7 +405,7 @@ public CompletableFuture<Boolean> exists() {
|
399 | 405 | Throwable e = err instanceof CompletionException ? err.getCause() : err;
|
400 | 406 | if (e instanceof ArangoDBException) {
|
401 | 407 | 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)) { |
403 | 409 | return false;
|
404 | 410 | }
|
405 | 411 | }
|
|
0 commit comments