错误
TMDB 风格调用返回 success 为 false 的错误体,含 status_code 和 status_message。OMDb 风格返回 Response False 和 Error。amodb 用 8 个状态码,只重试 429、500、504。
TMDB 风格的错误响应体
https:/ 返回的每个错误,都有与 TMDB 相同的 JSON 结构:
{
"success": false,
"status_code": 34,
"status_message": "The resource you requested could not be found."
}错误码
| HTTP | status_code | status_message | 应对方式 |
|---|---|---|---|
| 401 | 7 | Invalid API key: You must be granted a valid key. | 检查密钥及其发送方式。 |
| 401 | 10 | Suspended API key: Access to your account has been suspended, contact amodb. | 请写信至 support@amodb.dev。 |
| 402 | 36 | Your plan has expired. Renew at https://amodb.dev/pricing | 支付新的周期。 |
| 404 | 34 | The resource you requested could not be found. | 检查 ID 或路径。 |
| 405 | 37 | This method is not offered by amodb. | 使用读取接口。 |
| 429 | 25 | Your request count (N) is over the allowed limit of (L). | 等待 Retry-After 秒。 |
| 500 | 11 | Internal error: Something went wrong, contact amodb. | 几秒后重试。 |
| 504 | 24 | Your request to the backend server timed out. Try again. | 几秒后重试。 |
{
"Response": "False",
"Error": "Movie not found!"
}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或空数组。