|
30 | 30 | import com.platon.tx.ReadonlyTransactionManager; |
31 | 31 | import com.platon.tx.TransactionManager; |
32 | 32 | import com.platon.tx.exceptions.ContractCallException; |
| 33 | +import com.platon.tx.exceptions.PlatonCallException; |
| 34 | +import com.platon.tx.exceptions.PlatonCallTimeoutException; |
33 | 35 | import com.platon.tx.gas.ContractGasProvider; |
34 | 36 | import com.platon.tx.gas.GasProvider; |
35 | 37 | import com.platon.utils.JSONUtil; |
36 | 38 | import com.platon.utils.Numeric; |
| 39 | +import com.platon.utils.Strings; |
37 | 40 | import org.bouncycastle.util.encoders.Hex; |
38 | 41 | import org.slf4j.Logger; |
39 | 42 | import org.slf4j.LoggerFactory; |
@@ -87,6 +90,20 @@ private <T> CallResponse<T> executeCallObjectValueReturn(Function function, Clas |
87 | 90 | DefaultBlockParameterName.LATEST) |
88 | 91 | .send(); |
89 | 92 |
|
| 93 | + //判断底层返回的错误信息是否包含超时信息 |
| 94 | + if(ethCall.hasError()){ |
| 95 | + Response.Error error = ethCall.getError(); |
| 96 | + String message = error.getMessage(); |
| 97 | + String lowMessage = !Strings.isBlank(message)? message.toLowerCase() : null; |
| 98 | + //包含timeout则抛超时异常,其他错误则直接抛出runtime异常 |
| 99 | + if(!Strings.isBlank(lowMessage) |
| 100 | + && lowMessage.contains("timeout")){ |
| 101 | + throw new PlatonCallTimeoutException(error.getCode(),error.getMessage(),ethCall); |
| 102 | + } else { |
| 103 | + throw new PlatonCallException(error.getCode(),error.getMessage(),ethCall); |
| 104 | + } |
| 105 | + } |
| 106 | + |
90 | 107 | String result = Numeric.cleanHexPrefix(ethCall.getValue()); |
91 | 108 | if(result==null || "".equals(result)){ |
92 | 109 | throw new ContractCallException("Empty value (0x) returned from contract"); |
@@ -131,6 +148,20 @@ private <T> CallResponse<List<T>> executeCallListValueReturn(Function function, |
131 | 148 | DefaultBlockParameterName.LATEST) |
132 | 149 | .send(); |
133 | 150 |
|
| 151 | + //判断底层返回的错误信息是否包含超时信息 |
| 152 | + if(ethCall.hasError()){ |
| 153 | + Response.Error error = ethCall.getError(); |
| 154 | + String message = error.getMessage(); |
| 155 | + String lowMessage = !Strings.isBlank(message)? message.toLowerCase() : null; |
| 156 | + //包含timeout则抛超时异常,其他错误则直接抛出runtime异常 |
| 157 | + if(!Strings.isBlank(lowMessage) |
| 158 | + && lowMessage.contains("timeout")){ |
| 159 | + throw new PlatonCallTimeoutException(error.getCode(),error.getMessage(),ethCall); |
| 160 | + } else { |
| 161 | + throw new PlatonCallException(error.getCode(),error.getMessage(),ethCall); |
| 162 | + } |
| 163 | + } |
| 164 | + |
134 | 165 | String result = Numeric.cleanHexPrefix(ethCall.getValue()); |
135 | 166 | if(result==null || "".equals(result)){ |
136 | 167 | throw new ContractCallException("Empty value (0x) returned from contract"); |
|
0 commit comments