错误

TMDB 风格调用返回 success 为 false 的错误体,含 status_code 和 status_message。OMDb 风格返回 Response False 和 Error。amodb 用 8 个状态码,只重试 429、500、504。

更新于 以 Markdown 查看

TMDB 风格的错误响应体

https://api.amodb.dev/3 返回的每个错误,都有与 TMDB 相同的 JSON 结构:

JSON
{
  "success": false,
  "status_code": 34,
  "status_message": "The resource you requested could not be found."
}

错误码

HTTPstatus_codestatus_message应对方式
4017Invalid API key: You must be granted a valid key.检查密钥及其发送方式。
40110Suspended API key: Access to your account has been suspended, contact amodb.请写信至 support@amodb.dev。
40236Your plan has expired. Renew at https://amodb.dev/pricing支付新的周期。
40434The resource you requested could not be found.检查 ID 或路径。
40537This method is not offered by amodb.使用读取接口。
42925Your request count (N) is over the allowed limit of (L).等待 Retry-After 秒。
50011Internal error: Something went wrong, contact amodb.几秒后重试。
50424Your request to the backend server timed out. Try again.几秒后重试。

OMDb 风格的错误响应体

兼容 OMDb 的接口保持 OMDb 的结构和措辞:

带 r=xml 的 OMDb 调用返回 HTTP 400。请使用 r=json,或者省略 r。

JSON
{
  "Response": "False",
  "Error": "Movie not found!"
}
jspy
const res = await fetch("https://api.amodb.dev/3/movie/550", {
  headers: { Authorization: `Bearer ${process.env.AMODB_KEY}` },
});
if (!res.ok) {
  const err = await res.json();
  if (res.status === 429) {
    // wait Retry-After seconds, then retry
  }
  throw new Error(`amodb ${res.status} code ${err.status_code}: ${err.status_message}`);
}
res = requests.get(url, headers=headers, timeout=10)
if not res.ok:
    err = res.json()
    raise RuntimeError(f"amodb {res.status_code} code {err['status_code']}: {err['status_message']}")

不算错误的回退

  • 未知的 language 标签不会失败,amodb 会返回英语。
  • 没有数据的字段与 TMDB 一样,是 null 或空数组。