Skip to content

Commit 6d436e1

Browse files
authored
Merge pull request #130 from dchrzascik/issue-125-exception-message
Issue #125 Passing exception message to ArangoDBException
2 parents 51c158a + 78dbf3a commit 6d436e1

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;
@@ -1060,6 +1061,20 @@ public void getDocument() {
10601061
}
10611062
}
10621063

1064+
@Test
1065+
public void shouldIncludeExceptionMessage() {
1066+
final String exceptionMessage = "My error context";
1067+
final String action = "function (params) {"
1068+
+ "throw '" + exceptionMessage + "';"
1069+
+ "}";
1070+
try {
1071+
db.transaction(action, VPackSlice.class, null);
1072+
fail();
1073+
} catch (final ArangoDBException e) {
1074+
assertTrue(e.getException().contains(exceptionMessage));
1075+
}
1076+
}
1077+
10631078
@Test(expected = ArangoDBException.class)
10641079
public void getDocumentWrongId() {
10651080
db.getDocument("123", BaseDocument.class);

0 commit comments

Comments
 (0)