Skip to content

Commit 83b9c0b

Browse files
dchrzascikmpv1989
authored and
mpv1989
committed
Issue #125 Passing exception message to ArangoDBException
1 parent b048378 commit 83b9c0b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/main/java/com/arangodb/ArangoDBException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public String getErrorMessage() {
4949
return entity != null ? entity.getErrorMessage() : null;
5050
}
5151

52+
public String getException() {
53+
return entity != null ? entity.getException() : null;
54+
}
55+
5256
public int getResponseCode() {
5357
return entity != null ? entity.getCode() : null;
5458
}

src/main/java/com/arangodb/entity/ErrorEntity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
public class ErrorEntity {
2828

2929
private String errorMessage;
30+
private String exception;
3031
private int code;
3132
private int errorNum;
3233

@@ -41,6 +42,14 @@ public String getErrorMessage() {
4142
return errorMessage;
4243
}
4344

45+
/**
46+
* @return the exception message, passed when transaction fails
47+
* @return
48+
*/
49+
public String getException() {
50+
return exception;
51+
}
52+
4453
/**
4554
* @return the status code
4655
*/

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

Lines changed: 15 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;
@@ -1068,6 +1069,20 @@ public void getDocument() {
10681069
}
10691070
}
10701071

1072+
@Test
1073+
public void shouldIncludeExceptionMessage() {
1074+
final String exceptionMessage = "My error context";
1075+
final String action = "function (params) {"
1076+
+ "throw '" + exceptionMessage + "';"
1077+
+ "}";
1078+
try {
1079+
db.transaction(action, VPackSlice.class, null);
1080+
fail();
1081+
} catch (final ArangoDBException e) {
1082+
assertTrue(e.getException().contains(exceptionMessage));
1083+
}
1084+
}
1085+
10711086
@Test(expected = ArangoDBException.class)
10721087
public void getDocumentWrongId() {
10731088
db.getDocument("123", BaseDocument.class);

0 commit comments

Comments
 (0)