Skip to content

Commit 81f58c1

Browse files
dominiciampogo
authored andcommitted
sdk/java: expose data key for detailed error information
Closes #4065 Author: Dominic Dagradi <ddagradi@gmail.com> Date: Tue Jul 10 16:00:15 2018 -0700 upstream:98280ffe46a68fe90d33f61bc84f81deffa8af79
1 parent 81e84c6 commit 81f58c1

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

src/main/java/com/seq/exception/APIException.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import com.google.gson.annotations.SerializedName;
44
import com.google.gson.annotations.Expose;
55

6+
import java.util.List;
7+
import java.util.Map;
8+
69
/**
710
* APIException is thrown when the ledger API encounters an error handling a
811
* user request. Errors could be due to user error, or due to server issues.
@@ -27,12 +30,19 @@ public class APIException extends ChainException {
2730
public String chainMessage;
2831

2932
/**
30-
* Additional information about the error (possibly null).
33+
* Additional message about the error (possibly null).
3134
*/
3235
@Expose
3336
public String detail;
3437

3538
/**
39+
* Additional specifics about the error, such as which
40+
* action failed in a transaction, or for what reason (possibly null).
41+
*/
42+
@Expose
43+
public APIExceptionData data;
44+
45+
/**
3646
* Specifies whether the error is considered to be transient and that the
3747
* request should be retried.
3848
*/
@@ -57,6 +67,37 @@ public class APIException extends ChainException {
5767
@Expose
5868
public int statusCode;
5969

70+
/**
71+
* Additional specifics about the error, including any
72+
* nested sub-errors related to individual actions.
73+
*/
74+
public static class APIExceptionData {
75+
/**
76+
* Nested errors specific to individual actions in the transaction. Nested
77+
* errors may contain their own API exception data object.
78+
*/
79+
@Expose
80+
public List<APIException> actions;
81+
82+
/**
83+
* Lists fields omitted from an action.
84+
*/
85+
@Expose
86+
public List<String> missing_fields;
87+
88+
/**
89+
* The first field with incorrect data in an action .
90+
*/
91+
@Expose
92+
public String error_fields;
93+
94+
/**
95+
* The index in the transaction of the action with an error
96+
*/
97+
@Expose
98+
public Integer index;
99+
}
100+
60101
@Override
61102
public String getMessage() {
62103
String s = "";

src/test/java/com/seq/integration/FailureTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
import org.junit.Test;
1010

11-
import java.net.URL;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
import java.util.ArrayList;
1214

1315
import static org.junit.Assert.*;
1416

@@ -63,4 +65,28 @@ public void testTransact() throws Exception {
6365
}
6466
throw new Exception("expecting APIException");
6567
}
68+
69+
@Test
70+
public void testErrorData() throws Exception {
71+
client = TestUtils.generateClient();
72+
try {
73+
new Transaction.Builder().addAction(
74+
new Transaction.Builder.Action.Transfer()
75+
.setSourceAccountId("not-real")
76+
.setFlavorId("not-real")
77+
.setAmount(10)
78+
.setDestinationAccountId("not-real")
79+
).transact(client);
80+
} catch (APIException e) {
81+
assertEquals("SEQ706", e.seqCode);
82+
assertEquals(1, e.data.actions.size());
83+
84+
APIException actionError = e.data.actions.get(0);
85+
assertEquals("SEQ702", actionError.seqCode);
86+
assertEquals(0, (long)actionError.data.index);
87+
assertEquals("source_account_id", actionError.data.error_fields);
88+
return;
89+
}
90+
throw new Exception("expecting APIException");
91+
}
6692
}

0 commit comments

Comments
 (0)