1 package io.bytom.exception;
3 import com.google.gson.annotations.SerializedName;
6 * APIException wraps errors returned by the API.
7 * Each error contains a brief description in addition to a unique error code.<br>
8 * The error code can be used by Chain Support to diagnose the exact cause of the error.
9 * The mapping of error codes to messages is as follows:<br><br>
11 * <h2>General errors</h2>
12 * CH001 - Request timed out
14 * CH003 - Invalid request body
15 * CH004 - Invalid request header
18 * <h2>Account/Asset errors</h2>
19 * CH200 - Quorum must be greater than 1 and less than or equal to the length of xpubs
20 * CH201 - Invalid xpub format
21 * CH202 - At least one xpub is required
22 * CH203 - Retrieved type does not match expected type
24 * <h2>Access token errors</h2>
25 * CH300 - Malformed or empty access token id
26 * CH301 - Access tokens must be type client or network
27 * CH302 - Access token id is already in use
28 * CH310 - The access token used to authenticate this request cannot be deleted
30 * <h2>Query errors</h2>
31 * CH600 - Malformed pagination parameter `after`
32 * CH601 - Incorrect number of parameters to filter
33 * CH602 - Malformed query filter
35 * <h2>Transaction errors</h2>
36 * CH700 - Reference data does not match previous transaction's reference data<br>
37 * CH701 - Invalid action type<br>
38 * CH702 - Invalid alias on action<br>
39 * CH730 - Missing raw transaction<br>
40 * CH731 - Too many signing instructions in template for transaction<br>
41 * CH732 - Invalid transaction input index<br>
42 * CH733 - Invalid signature script component<br>
43 * CH734 - Missing signature in template<br>
44 * CH735 - Transaction rejected<br>
45 * CH760 - Insufficient funds for tx<br>
46 * CH761 - Some outputs are reserved; try again<br>
48 public class APIException extends BytomException {
50 * Unique identifier for the error.
55 * Message describing the general nature of the error.
57 @SerializedName("message")
58 public String chainMessage;
61 * Additional information about the error (possibly null).
66 * Specifies whether the error is temporary, or a change to the request is necessary.
68 public boolean temporary;
71 * Unique identifier of the request to the server.
73 public String requestId;
76 * HTTP status code returned by the server.
78 public int statusCode;
81 * Initializes exception with its message and requestId attributes.
82 * @param message error message
83 * @param requestId unique identifier of the request
85 public APIException(String message, String requestId) {
87 this.requestId = requestId;
91 * Intitializes exception with its code, message, detail & temporary field set.
92 * @param code error code
93 * @param message error message
94 * @param detail additional error information
95 * @param temporary unique identifier of the request
97 public APIException(String code, String message, String detail, boolean temporary) {
99 this.chainMessage = message;
101 this.detail = detail;
102 this.temporary = temporary;
106 * Initializes exception with its code, message, detail & requestId attributes.
107 * @param code error code
108 * @param message error message
109 * @param detail additional error information
110 * @param requestId unique identifier of the request
112 public APIException(String code, String message, String detail, String requestId) {
114 this.chainMessage = message;
116 this.detail = detail;
117 this.requestId = requestId;
121 * Initializes exception with all of its attributes.
122 * @param code error code
123 * @param message error message
124 * @param detail additional error information
125 * @param temporary specifies if the error is temporary
126 * @param requestId unique identifier of the request
127 * @param statusCode HTTP status code
137 this.chainMessage = message;
139 this.detail = detail;
140 this.temporary = temporary;
141 this.requestId = requestId;
142 this.statusCode = statusCode;
146 * Constructs a detailed message of the error.
147 * @return detailed error message
150 public String getMessage() {
153 if (this.code != null && this.code.length() > 0) {
154 s += "Code: " + this.code + " ";
157 s += "Message: " + this.chainMessage;
159 if (this.detail != null && this.detail.length() > 0) {
160 s += " Detail: " + this.detail;
163 if (this.requestId != null) {
164 s += " Request-ID: " + this.requestId;