获取返回结果
startFaceRecon 函数返回的 Promise 直接解析为带类型的对象——与 startOcr 不同,无需调用 JSON.parse()。
Promise 成功返回
type FACE_RECON_RETURN_VALUES = {
image_key: string;
device_scan_session_id: string;
};
| 属性 | 类型 | 说明 |
|---|---|---|
| image_key | string | 所提供图像的识别密钥,可在 QI Tech 系统的任何其他服务中使用。重要: 请保存该值,以便在验证类 API(例如 Onboarding API)中发送。 |
| device_scan_session_id | string | 人脸识别 SDK 内部执行的设备扫描会话的识别密钥,可在 QI Tech 系统的任何其他服务中使用。 |
{
"image_key": "5d0f0e1c-8f9e-4b6c-9c3d-2f8a1b4e7c10",
"device_scan_session_id": "a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d"
}
Promise 失败返回
失败时,Promise 会被 reject,并返回一个 FACE_RECON_ERROR 类型的对象:
type FACE_RECON_ERROR = {
status_code: number;
reason: string;
description: string;
};
| 属性 | 类型 | 说明 |
|---|---|---|
| status_code | number | 错误的 HTTP 状态码。 |
| reason | string | 错误原因的标识符。 |
| description | string | 错误的详细描述。 |
最常见的错误
| reason | status_code | description |
|---|---|---|
INVALID_TOKEN | 401 | Authentication token expired or invalid — client_session_key 无效或已过期。 |
USER_CANCELED | 0 | User canceled FaceRecon. — 用户在完成流程前中断了流程。 |
处理示例
startFaceRecon(CAAS_ENVIRONMENT.SANDBOX, clientSessionKey)
.then((response) => {
console.log('Image Key: ', response.image_key);
console.log('Device Scan Session Id: ', response.device_scan_session_id);
})
.catch((error) => {
// 可选:将错误断言(cast)为 FACE_RECON_ERROR。
// 建议这样做以保证 TypeScript 的类型安全。
const reconError = error as FACE_RECON_ERROR;
console.error('Status:', reconError.status_code);
console.error('Reason:', reconError.reason);
console.error('Description:', reconError.description);
});