Skip to content

Commit 072e608

Browse files
committed
improve ContractCallException error message
1 parent f88e4ef commit 072e608

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

chainsql/src/main/java/com/peersafe/chainsql/contract/Contract.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,12 @@ private List<Type> executeCall(
115115
JSONObject objTx = prepareCallParam(function);
116116

117117
JSONObject ret = this.chainsql.connection.client.contractCall(objTx);
118-
if(ret.has("error")){
119-
throw new ContractCallException(ret.getString("error"));
118+
if(ret.has("error") && ret.has("error_message")){
119+
throw new ContractCallException(ret.getString("error"),ret.getString("error_message"));
120+
}else if(ret.has("error")){
121+
throw new ContractCallException(ret.getString("error"));
120122
}
123+
121124
return FunctionReturnDecoder.decode(ret.getString("contract_call_result"), function.getOutputParameters());
122125
}
123126

chainsql/src/main/java/com/peersafe/chainsql/contract/exception/ContractCallException.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* Exception resulting from issues calling methods on Smart Contracts.
55
*/
66
public class ContractCallException extends RuntimeException {
7-
public int error_code;
8-
public ContractCallException(String message) {
9-
super(message);
7+
public String error;
8+
public ContractCallException(String error) {
9+
super(error);
1010
}
11-
public ContractCallException(String message,int error_code) {
12-
super(message);
13-
this.error_code = error_code;
11+
public ContractCallException(String error,String error_message) {
12+
super(error_message);
13+
this.error = error;
1414
}
1515
public ContractCallException(String message, Throwable cause) {
1616
super(message, cause);

0 commit comments

Comments
 (0)