跳转到主要内容

API 状态代码

API 状态代码是服务器返回的代码,如 200、404、429、500、502。

API 错误代码

API 返回以下错误代码集:
  • DefaultError = 1000,
  • FailedToBuildTransactionError = 1001,
  • NoQuoteError = 1002,
  • NotFoundError = 1003,
  • NotProcessableError = 1004,
  • RateLimitError = 1005,
  • ServerError = 1006,
  • SlippageError = 1007,
  • ThirdPartyError = 1008,
  • TimeoutError = 1009,
  • UnauthorizedError = 1010,
  • ValidationError = 1011,
  • RpcFailure = 1012,
  • MalformedSchema = 1013,

工具错误

除了返回状态和错误代码外,API 还可能返回底层工具的错误消息,描述特定工具的问题。这可能由许多原因引起,从工具简单地不支持请求的代币对或流动性不足。 为了更好地解释失败情况,我们尝试以可预测的格式返回错误。ToolError 接口如下所示:
type ToolErrorType = 'NO_QUOTE'

interface ToolError {
  errorType: ToolErrorType
  code: string
  action: Action
  tool: string
  message: string
}

可能的代码:

NO_POSSIBLE_ROUTE:未找到此操作的路由。 INSUFFICIENT_LIQUIDITY:工具的流动性不足。 TOOL_TIMEOUT:第三方工具超时。 UNKNOWN_ERROR:发生未知错误。 RPC_ERROR:获取链上数据时出现问题。请稍后重试。 AMOUNT_TOO_LOW:初始金额太低,无法使用此工具进行转账。 AMOUNT_TOO_HIGH:初始金额太高,无法使用此工具进行转账。 FEES_HGHER_THAN_AMOUNT:费用高于初始金额——这将导致负的结果代币。 DIFFERENT_RECIPIENT_NOT_SUPPORTED:此工具不支持不同的接收方地址。 TOOL_SPECIFIC_ERROR:第三方工具返回错误。 CANNOT_GUARANTEE_MIN_AMOUNT:工具无法保证满足最小金额。

示例响应:

{
    "message": "Unable to find a quote for the requested transfer.",
    "errors": [
        {
            "errorType": "NO_QUOTE",
            "code": "INSUFFICIENT_LIQUIDITY",
            "action": {
                "fromChainId": 100,
                "toChainId": 100,
                "fromToken": {
                    "address": "0x4ecaba5870353805a9f068101a40e0f32ed605c6",
                    "decimals": 6,
                    "symbol": "USDT",
                    "chainId": 100,
                    "coinKey": "USDT",
                    "name": "USDT",
                    "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png",
                    "priceUSD": "0.99872"
                },
                "toToken": {
                    "address": "0xddafbb505ad214d7b80b1f830fccc89b60fb7a83",
                    "decimals": 6,
                    "symbol": "USDC",
                    "chainId": 100,
                    "coinKey": "USDC",
                    "name": "USDC",
                    "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png"
                },
                "fromAmount": "1",
                "slippage": 0.03,
                "fromAddress": "0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0",
                "toAddress": "0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0"
            },
            "tool": "1inch",
            "message": "The tool's liquidity is insufficient."
        },
        {
            "errorType": "NO_QUOTE",
            "code": "TOOL_TIMEOUT",
            "action": {
                "fromChainId": 100,
                "toChainId": 100,
                "fromToken": {
                    "address": "0x4ecaba5870353805a9f068101a40e0f32ed605c6",
                    "decimals": 6,
                    "symbol": "USDT",
                    "chainId": 100,
                    "coinKey": "USDT",
                    "name": "USDT",
                    "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png",
                    "priceUSD": "0.99872"
                },
                "toToken": {
                    "address": "0xddafbb505ad214d7b80b1f830fccc89b60fb7a83",
                    "decimals": 6,
                    "symbol": "USDC",
                    "chainId": 100,
                    "coinKey": "USDC",
                    "name": "USDC",
                    "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png"
                },
                "fromAmount": "1",
                "slippage": 0.03,
                "fromAddress": "0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0",
                "toAddress": "0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0"
            },
            "tool": "openocean",
            "message": "The third party tool timed out."
        },
        {
            "errorType": "NO_QUOTE",
            "code": "NO_POSSIBLE_ROUTE",
            "action": {
                "fromChainId": 100,
                "toChainId": 100,
                "fromToken": {
                    "address": "0x4ecaba5870353805a9f068101a40e0f32ed605c6",
                    "decimals": 6,
                    "symbol": "USDT",
                    "chainId": 100,
                    "coinKey": "USDT",
                    "name": "USDT",
                    "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png",
                    "priceUSD": "0.99872"
                },
                "toToken": {
                    "address": "0xddafbb505ad214d7b80b1f830fccc89b60fb7a83",
                    "decimals": 6,
                    "symbol": "USDC",
                    "chainId": 100,
                    "coinKey": "USDC",
                    "name": "USDC",
                    "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png"
                },
                "fromAmount": "1",
                "slippage": 0.03,
                "fromAddress": "0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0",
                "toAddress": "0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0"
            },
            "tool": "superfluid",
            "message": "No route was found for this action."
        }
    ]
}
I