Skip to content

Issue #125 Passing exception message to ArangoDBException #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/com/arangodb/ArangoDBException.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public String getErrorMessage() {
return entity != null ? entity.getErrorMessage() : null;
}

public String getException() {
return entity != null ? entity.getException() : null;
}

public int getResponseCode() {
return entity != null ? entity.getCode() : null;
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/arangodb/entity/ErrorEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
public class ErrorEntity {

private String errorMessage;
private String exception;
private int code;
private int errorNum;

Expand All @@ -41,6 +42,14 @@ public String getErrorMessage() {
return errorMessage;
}

/**
* @return the exception message, passed when transaction fails
* @return
*/
public String getException() {
return exception;
}

/**
* @return the status code
*/
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/arangodb/ArangoDatabaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
Expand Down Expand Up @@ -1060,6 +1061,20 @@ public void getDocument() {
}
}

@Test
public void shouldIncludeExceptionMessage() {
final String exceptionMessage = "My error context";
final String action = "function (params) {"
+ "throw '" + exceptionMessage + "';"
+ "}";
try {
db.transaction(action, VPackSlice.class, null);
fail();
} catch (final ArangoDBException e) {
assertTrue(e.getException().contains(exceptionMessage));
}
}

@Test(expected = ArangoDBException.class)
public void getDocumentWrongId() {
db.getDocument("123", BaseDocument.class);
Expand Down