跳转到主要内容

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_HIGHER_THAN_AMOUNT:费用高于初始金额 — 这将导致负面的结果代币。 DIFFERENT_RECIPIENT_NOT_SUPPORTED:此工具不支持不同的接收地址。 TOOL_SPECIFIC_ERROR:第三方工具返回错误。 CANNOT_GUARANTEE_MIN_AMOUNT:工具不能保证会达到最小金额。

示例响应:

{
    "message": "无法为请求的转移找到报价。",
    "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": "工具的流动性不足。"
        },
        {
            "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": "第三方工具超时。"
        },
        {
            "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": "没有找到此操作的路由。"
        }
    ]
}