入門
錯誤
錯誤以 JSON 回傳,附帶可用於比對的固定錯誤碼。
錯誤格式
- errorstring
可用於比對的固定錯誤碼。
- messagestring
可讀的說明。
- detailsobject
僅限批量 400:無效的輸入。
{
"error": "invalid_ip",
"message": "Invalid IP address format"
}狀態碼
- 400bad_request, invalid_ip, reserved_ip, invalid_domain, invalid_target, unresolved_host, unknown_jurisdiction, invalid_asn
請求或某項輸入無效。
- 401missing_api_key, invalid_api_key, unauthorized
API 金鑰缺失或無效。
- 403account_suspended
帳戶已被暫停。
- 404not_found
該路徑或 id 不存在。
- 413too_many_lines
請求主體或清單過大。
- 429rate_limit_exceeded
速率限制已用盡。
- 500server_error
我們這邊發生故障;請稍後重試。
SDK 中的錯誤
- APIError
任何錯誤回應,包含 status、code 及 message。
- AuthenticationError
401 或 403。
- NotFoundError
404。
- RateLimitError
429,包含 reason、retryAfter 及升級連結。
- ConnectionError
未收到回應,包括逾時。
import IPScanner, { APIError, RateLimitError } from '@ipscanner.io/sdk';
const client = new IPScanner({ apiKey: 'YOUR_API_KEY' });
try {
await client.ip.lookup('8.8.8.8');
} catch (err) {
if (err instanceof RateLimitError) {
console.log(err.reason, err.retryAfter, err.upgradeUrl);
} else if (err instanceof APIError) {
console.log(err.status, err.code, err.message);
} else {
throw err;
}
}