Skip to content

Commit 9c20153

Browse files
authored
Merge pull request #5 from dchrzascik/issue-4
Issue #4 Passing transaction exception message to future's result
2 parents e04e039 + e7ccb2e commit 9c20153

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/main/java/com/arangodb/internal/velocystream/VstCommunicationAsync.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ public CompletableFuture<Response> execute(final Request request, final Connecti
140140
if (response.getResponseCode() >= 300) {
141141
if (response.getBody() != null) {
142142
final ErrorEntity errorEntity = util.deserialize(response.getBody(), ErrorEntity.class);
143-
final String errorMessage = String.format("Response: %s, Error: %s - %s",
144-
errorEntity.getCode(), errorEntity.getErrorNum(), errorEntity.getErrorMessage());
145-
rfuture.completeExceptionally(new ArangoDBException(errorMessage));
143+
rfuture.completeExceptionally(new ArangoDBException(errorEntity));
146144
} else {
147145
rfuture.completeExceptionally(new ArangoDBException(
148146
String.format("Response Code: %s", response.getResponseCode())));

src/test/java/com/arangodb/ArangoDatabaseTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static org.hamcrest.Matchers.is;
2929
import static org.hamcrest.Matchers.not;
3030
import static org.junit.Assert.assertThat;
31+
import static org.junit.Assert.assertTrue;
3132
import static org.junit.Assert.fail;
3233

3334
import java.io.IOException;
@@ -38,6 +39,7 @@
3839
import java.util.Iterator;
3940
import java.util.Map;
4041
import java.util.concurrent.CompletableFuture;
42+
import java.util.concurrent.CompletionException;
4143
import java.util.concurrent.ExecutionException;
4244
import java.util.concurrent.atomic.AtomicInteger;
4345

@@ -1029,6 +1031,26 @@ public void getDocument() throws InterruptedException, ExecutionException {
10291031
}
10301032
}
10311033

1034+
1035+
@Test
1036+
public void shouldIncludeExceptionMessage() {
1037+
final String exceptionMessage = "My error context";
1038+
final String action = "function (params) {"
1039+
+ "throw '" + exceptionMessage + "';"
1040+
+ "}";
1041+
try {
1042+
db.transaction(action, VPackSlice.class, null).join();
1043+
fail();
1044+
} catch (final CompletionException e) {
1045+
Throwable cause = e.getCause();
1046+
if (cause instanceof ArangoDBException) {
1047+
assertTrue(((ArangoDBException) cause).getException().equals(exceptionMessage));
1048+
} else {
1049+
fail("Root cause expected to be an ArangoDBException");
1050+
}
1051+
}
1052+
}
1053+
10321054
@Test(expected = ArangoDBException.class)
10331055
public void getDocumentWrongId() throws InterruptedException, ExecutionException {
10341056
db.getDocument("123", BaseDocument.class).get();

0 commit comments

Comments
 (0)