|
30 | 30 | import java.util.Collection; |
31 | 31 | import java.util.Objects; |
32 | 32 | import java.util.concurrent.CompletableFuture; |
33 | | -import java.util.concurrent.CompletionException; |
34 | | -import java.util.function.Function; |
35 | 33 |
|
36 | 34 | /** |
37 | 35 | * @author Mark Vollmary |
@@ -116,29 +114,7 @@ public <T> CompletableFuture<T> getDocument( |
116 | 114 | DocumentUtil.validateDocumentKey(key); |
117 | 115 | boolean isCatchException = options != null ? options.isCatchException() : new DocumentReadOptions().isCatchException(); |
118 | 116 | return (CompletableFuture<T>) executor.execute(getDocumentRequest(key, options), type) |
119 | | - .exceptionally(handleGetDocumentExceptions(isCatchException)); |
120 | | - } |
121 | | - |
122 | | - private <T> Function<Throwable, T> handleGetDocumentExceptions(Boolean isCatchException) { |
123 | | - return throwable -> { |
124 | | - if (throwable instanceof CompletionException) { |
125 | | - if (throwable.getCause() instanceof ArangoDBException) { |
126 | | - ArangoDBException arangoDBException = (ArangoDBException) throwable.getCause(); |
127 | | - |
128 | | - // handle Response: 404, Error: 1655 - transaction not found |
129 | | - if (arangoDBException.getErrorNum() != null && arangoDBException.getErrorNum() == 1655) { |
130 | | - throw (CompletionException) throwable; |
131 | | - } |
132 | | - |
133 | | - if ((arangoDBException.getResponseCode() != null && (arangoDBException.getResponseCode() == 404 || arangoDBException.getResponseCode() == 304 |
134 | | - || arangoDBException.getResponseCode() == 412)) && isCatchException) { |
135 | | - return null; |
136 | | - } |
137 | | - } |
138 | | - throw (CompletionException) throwable; |
139 | | - } |
140 | | - throw new CompletionException(throwable); |
141 | | - }; |
| 117 | + .exceptionally(ExceptionUtil.catchGetDocumentExceptions(isCatchException)); |
142 | 118 | } |
143 | 119 |
|
144 | 120 | @Override |
@@ -260,7 +236,7 @@ public CompletableFuture<Boolean> documentExists(final String key) { |
260 | 236 | public CompletableFuture<Boolean> documentExists(final String key, final DocumentExistsOptions options) { |
261 | 237 | boolean isCatchException = options != null ? options.isCatchException() : new DocumentExistsOptions().isCatchException(); |
262 | 238 | return executor.execute(documentExistsRequest(key, options), response -> response) |
263 | | - .exceptionally(handleGetDocumentExceptions(isCatchException)) |
| 239 | + .exceptionally(ExceptionUtil.catchGetDocumentExceptions(isCatchException)) |
264 | 240 | .thenApply(Objects::nonNull); |
265 | 241 | } |
266 | 242 |
|
|
0 commit comments