错误类型
所有 API 错误都会抛出继承自UQPayError 的带类型错误类:
import {
AuthenticationError,
ValidationError,
NotFoundError,
RateLimitError,
ServerError,
NetworkError,
SimulatorNotAvailableError,
} from '@uqpay/sdk'
| 字段 | 类型 | 说明 |
|---|---|---|
message | string | 可读的错误描述 |
httpStatus | number | HTTP 状态码 |
type | string | API 错误类型标识 |
code | string | API 错误码 |
捕获错误
try {
const account = await client.account.accounts.retrieve('acc-123')
} catch (err) {
if (err instanceof NotFoundError) {
console.log('Account not found')
} else if (err instanceof ValidationError) {
console.log('Bad request:', err.message)
} else if (err instanceof RateLimitError) {
console.log('Rate limited, will retry automatically')
} else if (err instanceof NetworkError) {
console.log('Network error:', err.message)
} else if (err instanceof SimulatorNotAvailableError) {
console.log('Simulator is only available in sandbox')
}
}
重试
SDK 会对服务端错误、限流和网络错误按指数退避自动重试。 全局或单次配置重试:// Global — set when creating the client
const client = new UQPayClient({
// ...
maxRetries: 3,
})
// Per request — overrides the global setting
await client.account.accounts.retrieve('acc-123', { maxRetries: 0 })

