Collecting the Responses
The startFaceRecon function returns a Promise that resolves with an already-typed object — unlike startOcr, there is no need to call JSON.parse().
Promise resolution
type FACE_RECON_RETURN_VALUES = {
image_key: string;
device_scan_session_id: string;
};
| Attribute | Type | Description |
|---|---|---|
| image_key | string | Identification key of the provided image, which can be used in any other service of the QI Tech system. Important: store this value to send in the validation APIs (e.g. the Onboarding API). |
| device_scan_session_id | string | Identification key of the device scan session performed internally by the Face Recognition SDK, which can be used in any other service of the QI Tech system. |
{
"image_key": "5d0f0e1c-8f9e-4b6c-9c3d-2f8a1b4e7c10",
"device_scan_session_id": "a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d"
}
Promise rejection
On failure, the Promise is rejected with an object of type FACE_RECON_ERROR:
type FACE_RECON_ERROR = {
status_code: number;
reason: string;
description: string;
};
| Attribute | Type | Description |
|---|---|---|
| status_code | number | HTTP status code of the error. |
| reason | string | Identifier of the error reason. |
| description | string | Detailed description of the error. |
Most common errors
| reason | status_code | description |
|---|---|---|
INVALID_TOKEN | 401 | Authentication token expired or invalid — the client_session_key is invalid or has expired. |
USER_CANCELED | 0 | User canceled FaceRecon. — the user interrupted the flow before completing it. |
Handling example
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) => {
// Optional: type assertion (cast) to FACE_RECON_ERROR.
// Recommended to ensure type safety in TypeScript.
const reconError = error as FACE_RECON_ERROR;
console.error('Status:', reconError.status_code);
console.error('Reason:', reconError.reason);
console.error('Description:', reconError.description);
});