Error Handling
During the Vitals™ scan, there might be errors thrown via the onVideoFrameProcessed
callback function. In summary, there are 4 major types of error as listed below.
ErrorError | DescriptionDescription |
---|---|
Face Lost | During the 25-second Collecting Data stage, Vitals™ SDK attempts to detect face on every camera frame. When the face cannot be detected, an error will be thrown. |
Network / HTTPS Request Error | During the Analyzing Data stage, an HTTPS request is made to the Vitals™ Cloud Service. If the network is disconnected or unstable, the request will fail and an error will be thrown. |
No Blink | (If Applicable) During the 25-second Collecting Data stage, the user should blink at least once. This is to avoid people using a photo to do the scanning. If no blink is performed during the 25-second scan, an error will be thrown at the start of the Analyzing Data stage. |
Others | There are other potential errors during the Vitals™ Health Assessment (aka VHA) process, e.g., invalid user ID, invalid API Key, server-side errors, etc. |
TIP
For a better user experience, once an error occurred, you should display the error to let the user knows what made the scan stopped. You can also call stopScanning()
to ensure the scan must be stopped.
Target SDK
TIP
You can refer to the sample code and the API Reference for more details. Most related API(s) include: VideoFrameProcessedEvent
and ScanResult
.
There are 2 ways you can obtain the errors with JavaScript SDK, you can choose either way and they are giving the same errors.
With onVideoFrameProcessed
You can observe any errors from the JavaScript SDK through the onVideoFrameProcessed
callback function.
Use the event.healthResult?.error
property from the callback function and display the error in any format you need in your product when it occurs.
/* Update the onload event handler function */
window.onload = () => {
/* A reference of the camera that should have been created in the "Camera Setup" step. */
const cam = createVitalSignCamera({ isActive: true, config, userInfo })
// ...
/* Update the onVideoFrameProcessed callback function */
cam.onVideoFrameProcessed = (event : VideoFrameProcessedEvent) => {
// ...
/* Print error to console (if any) */
if (event.healthResult?.error) {
console.log(event.healthResult?.error);
}
}
}
/* Update the onload event handler function */
window.onload = () => {
/* A reference of the camera that should have been created in the "Camera Setup" step. */
const cam = createVitalSignCamera({ isActive: true, config, userInfo })
// ...
/* Update the onVideoFrameProcessed callback function */
cam.onVideoFrameProcessed = (event) => {
// ...
/* Print error to console (if any) */
if (event.healthResult?.error) {
console.log(event.healthResult?.error);
}
}
}
With onError
You can register an onError
handler with the Vital Sign Camera component, for example:
/* Update the onload event handler function */
window.onload = () => {
/* A reference of the camera that should have been created in the "Camera Setup" step. */
const cam = createVitalSignCamera({ isActive: true, config, userInfo })
// ...
/* Add an onError handler for the Vital Sign Camera */
cam.onError = (err) => {
/* Print error to console (if any) */
if (err) {
console.log(err);
}
}
}
/* Update the onload event handler function */
window.onload = () => {
/* A reference of the camera that should have been created in the "Camera Setup" step. */
const cam = createVitalSignCamera({ isActive: true, config, userInfo })
// ...
/* Add an onError handler for the Vital Sign Camera */
cam.onError = (err) => {
/* Print error to console (if any) */
if (err) {
console.log(err);
}
}
}