All Products
Search
Document Center

Blockchain as a Service:Error messages

Last Updated:May 08, 2020

If the result of a transaction shows that the transaction is executed incorrectly, you can locate the cause based on the error code.

  • The errorCode field in response indicates the cause of a transaction sending or execution error.
  • When the sent request is transaction-related, you can obtain a more detailed error code about the transaction execution error based on the transaction return value.

The following shows a contract deployment example.

  1. // Synchronous execution.
  2. DeployContractResponse response = sdk.getContractService().deployContract(request);
  3. // Indicates whether the transaction is sent successfully. If the transaction fails to be sent, use result.getErrorCode() to obtain the error code.
  4. assertTrue(response.isSuccess());
  5. // 0 indicates successful transaction execution, and a non-zero value indicates a transaction execution failure. Locate the cause from the ErrorCode object based on the result value.
  6. assertEquals(0, response.getTransactionReceipt().getResult());
  7. // Asynchronous execution.
  8. int result = sdk.getContractService().asyncDeployContract(
  9. request,
  10. new IAsyncCallback() {
  11. @Override
  12. public void onResponse(int errorCode, Response response) {
  13. // If errorCode is 0, a response has been received from the platform. 20072 indicates a message timeout. 30018 indicates that the number of messages exceeds the maximum queue size. (Set a value for NetworkOption.threadPoolQueueSize as required.)
  14. assertEquals(0, errorCode);
  15. // Indicates whether the transaction is sent successfully. If the transaction fails to be sent, use result.getErrorCode() to obtain the error code.
  16. assertTrue(response.isSuccess());
  17. // 0 indicates successful transaction execution, and a non-zero value indicates a transaction execution failure. Locate the cause from the ErrorCode object based on the result value.
  18. // The response to the callback needs to be converted into the response to the request. For example, DeployContractRequest corresponds to DeployContractResponse.
  19. assertEquals(0, deployContractResponse.getTransactionReceipt().getResult());
  20. }
  21. });