跳转到主要内容

HTTP 状态码

状态含义可重试
200成功不适用
400错误请求(无效参数、无效代币地址、不支持的代币程序)
401未授权(缺少或无效的 API 密钥)
404不支持的市场或代币地址尚未索引否(见下文)
422无法处理(有效请求但无可用路由)
429速率限制
502网关错误(上游 RPC 或 DEX 故障)
503服务不可用(路由器未就绪或已暂停)
500内部服务器错误

响应信封

成功

{
  "status": "ok",
  "tx": "base64-encoded unsigned transaction",
  "route": { "market_type": "pumpswap", "pool_id": "..." }
}

不支持的市场

当代币在任何支持的 DEX 上没有可用路由时返回。message 字段提供人类和 AI 可读的说明。
{
  "status": "unsupported",
  "reason": "no_route",
  "message": "No supported market found for this mint. Supported DEXs: PumpSwap, Raydium (CPMM, Launchpad), Meteora (DBC, DAMM v2), Pump.fun."
}
原因状态说明
no_route404没有支持的 DEX 有此代币的池
invalid_mint400代币地址在链上不存在
unsupported_token_program400代币使用 SPL Token 或 Token-2022 以外的程序

未索引

当代币存在但尚未解析时返回。短暂延迟后重试。
{
  "status": "not_indexed",
  "mint": "So11111111111111111111111111111111111111112",
  "reason": "mint not indexed yet; try again shortly"
}

错误

验证失败、速率限制和服务器错误的通用错误响应。
{
  "error": "descriptive error message"
}
SDK 解析所有响应变体,并通过 ExitApiError 类型呈现。

ExitApiError 类型

每个 SDK 都暴露一个带有 kind 判别器的 ExitApiError(或等效类型):
Kind触发条件可重试
transport网络故障、DNS 错误、超时
http_status非 2xx HTTP 响应状态 >= 500 或 429 时是
envelope_status服务器返回 { "status": "error" }
parse响应体无法解析为 JSON

检查可重试性

import { ExitApiError } from "@lasersell/lasersell-sdk";

try {
  const response = await client.buildSellTx(request);
} catch (error) {
  if (error instanceof ExitApiError) {
    console.log("Kind:", error.kind);
    console.log("Retryable:", error.isRetryable());
    console.log("HTTP status:", error.status);
    console.log("Body:", error.body);
  }
}

内置重试行为

所有 SDK 包含自动重试,默认值如下:
设置默认值
最大尝试次数2
初始退避25 ms
最大退避25 ms
抖动25 ms
连接超时200 ms
尝试超时900 ms
重试仅在 isRetryable() 返回 true 时触发(传输故障、5xx 响应和 429 速率限制)。

自定义重试策略

const client = ExitApiClient.withOptions("YOUR_API_KEY", {
  attempt_timeout_ms: 2000,
  retry_policy: {
    max_attempts: 3,
    initial_backoff_ms: 50,
    max_backoff_ms: 200,
    jitter_ms: 50,
  },
});

最佳实践

  • 不要重试 400401422 错误。这些表示必须在代码中修复的请求或认证问题。
  • 不要重试 404"status": "unsupported" 的响应。该代币没有支持的市场。
  • 重试一次 404"status": "not_indexed" 的响应。代币可能需要一点时间来解析。
  • 指数退避 429 响应。内置重试自动处理。
  • 带退避重试 502503 错误。这些是暂时的基础设施问题。
  • 记录错误详情,包括 kindstatusbody 以便调试。
  • 如果持续看到 envelope_status 错误,验证你的 mint 地址和 user_pubkey 是否正确。