@hexar/biometric-identity-sdk-core 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BiometricIdentitySDK.js +35 -9
- package/package.json +1 -1
- package/src/BiometricIdentitySDK.ts +36 -12
|
@@ -287,10 +287,10 @@ class BiometricIdentitySDK {
|
|
|
287
287
|
const compressedFrame = this.fixBase64Padding(await this.compressImage(frame));
|
|
288
288
|
validFrames.push(compressedFrame);
|
|
289
289
|
}
|
|
290
|
-
const MIN_FRAMES =
|
|
290
|
+
const MIN_FRAMES = 5;
|
|
291
291
|
if (validFrames.length < MIN_FRAMES) {
|
|
292
292
|
logger_1.logger.error(`Insufficient valid frames: ${validFrames.length} < ${MIN_FRAMES}`);
|
|
293
|
-
throw this.createError(types_1.BiometricErrorCode.
|
|
293
|
+
throw this.createError(types_1.BiometricErrorCode.LIVENESS_CHECK_FAILED, 'Not enough valid video frames captured. Please try again.');
|
|
294
294
|
}
|
|
295
295
|
/**
|
|
296
296
|
* Perform backend validation
|
|
@@ -456,14 +456,40 @@ class BiometricIdentitySDK {
|
|
|
456
456
|
errorData: error?.errorData,
|
|
457
457
|
errorStack: error?.stack?.substring(0, 500)
|
|
458
458
|
});
|
|
459
|
-
//
|
|
459
|
+
// Categorise the error properly instead of lumping everything as NETWORK_ERROR
|
|
460
460
|
const isTimeout = error?.message?.includes('timeout') || error?.message?.includes('Request timeout') || error?.message?.includes('AbortError');
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
461
|
+
const isNetwork = error?.message?.includes('Network request failed') || error?.message?.includes('Failed to fetch') || error?.message?.includes('NETWORK_ERROR');
|
|
462
|
+
let errorCode;
|
|
463
|
+
let errorMessage;
|
|
464
|
+
let status;
|
|
465
|
+
let statusText;
|
|
466
|
+
if (isTimeout) {
|
|
467
|
+
errorCode = types_1.BiometricErrorCode.VALIDATION_TIMEOUT;
|
|
468
|
+
errorMessage = 'La validación está tomando demasiado tiempo. Por favor, intenta nuevamente.';
|
|
469
|
+
status = 504;
|
|
470
|
+
statusText = 'Gateway Timeout';
|
|
471
|
+
}
|
|
472
|
+
else if (isNetwork) {
|
|
473
|
+
errorCode = types_1.BiometricErrorCode.NETWORK_ERROR;
|
|
474
|
+
errorMessage = error?.message || 'Network error';
|
|
475
|
+
status = error?.status;
|
|
476
|
+
statusText = error?.statusText;
|
|
477
|
+
}
|
|
478
|
+
else if (error?.message?.includes('liveness') || error?.message?.includes('Liveness')) {
|
|
479
|
+
errorCode = types_1.BiometricErrorCode.LIVENESS_CHECK_FAILED;
|
|
480
|
+
errorMessage = error?.message || 'Liveness check failed';
|
|
481
|
+
status = error?.status;
|
|
482
|
+
statusText = error?.statusText;
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
errorCode = types_1.BiometricErrorCode.UNKNOWN_ERROR;
|
|
486
|
+
errorMessage = error?.message || (error?.status ? `Backend request failed with status ${error.status}` : 'Backend validation failed');
|
|
487
|
+
status = error?.status;
|
|
488
|
+
statusText = error?.statusText;
|
|
489
|
+
}
|
|
490
|
+
const errorToThrow = this.createError(errorCode, errorMessage, {
|
|
491
|
+
status,
|
|
492
|
+
statusText,
|
|
467
493
|
errorData: error?.errorData,
|
|
468
494
|
originalError: error?.message
|
|
469
495
|
});
|
package/package.json
CHANGED
|
@@ -376,12 +376,12 @@ export class BiometricIdentitySDK {
|
|
|
376
376
|
validFrames.push(compressedFrame);
|
|
377
377
|
}
|
|
378
378
|
|
|
379
|
-
const MIN_FRAMES =
|
|
379
|
+
const MIN_FRAMES = 5;
|
|
380
380
|
if (validFrames.length < MIN_FRAMES) {
|
|
381
381
|
logger.error(`Insufficient valid frames: ${validFrames.length} < ${MIN_FRAMES}`);
|
|
382
382
|
throw this.createError(
|
|
383
|
-
BiometricErrorCode.
|
|
384
|
-
'
|
|
383
|
+
BiometricErrorCode.LIVENESS_CHECK_FAILED,
|
|
384
|
+
'Not enough valid video frames captured. Please try again.'
|
|
385
385
|
);
|
|
386
386
|
}
|
|
387
387
|
|
|
@@ -579,19 +579,43 @@ export class BiometricIdentitySDK {
|
|
|
579
579
|
errorStack: error?.stack?.substring(0, 500)
|
|
580
580
|
});
|
|
581
581
|
|
|
582
|
-
//
|
|
582
|
+
// Categorise the error properly instead of lumping everything as NETWORK_ERROR
|
|
583
583
|
const isTimeout = error?.message?.includes('timeout') || error?.message?.includes('Request timeout') || error?.message?.includes('AbortError');
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
584
|
+
const isNetwork = error?.message?.includes('Network request failed') || error?.message?.includes('Failed to fetch') || error?.message?.includes('NETWORK_ERROR');
|
|
585
|
+
|
|
586
|
+
let errorCode: BiometricErrorCode;
|
|
587
|
+
let errorMessage: string;
|
|
588
|
+
let status: number | undefined;
|
|
589
|
+
let statusText: string | undefined;
|
|
590
|
+
|
|
591
|
+
if (isTimeout) {
|
|
592
|
+
errorCode = BiometricErrorCode.VALIDATION_TIMEOUT;
|
|
593
|
+
errorMessage = 'La validación está tomando demasiado tiempo. Por favor, intenta nuevamente.';
|
|
594
|
+
status = 504;
|
|
595
|
+
statusText = 'Gateway Timeout';
|
|
596
|
+
} else if (isNetwork) {
|
|
597
|
+
errorCode = BiometricErrorCode.NETWORK_ERROR;
|
|
598
|
+
errorMessage = error?.message || 'Network error';
|
|
599
|
+
status = error?.status;
|
|
600
|
+
statusText = error?.statusText;
|
|
601
|
+
} else if (error?.message?.includes('liveness') || error?.message?.includes('Liveness')) {
|
|
602
|
+
errorCode = BiometricErrorCode.LIVENESS_CHECK_FAILED;
|
|
603
|
+
errorMessage = error?.message || 'Liveness check failed';
|
|
604
|
+
status = error?.status;
|
|
605
|
+
statusText = error?.statusText;
|
|
606
|
+
} else {
|
|
607
|
+
errorCode = BiometricErrorCode.UNKNOWN_ERROR;
|
|
608
|
+
errorMessage = error?.message || (error?.status ? `Backend request failed with status ${error.status}` : 'Backend validation failed');
|
|
609
|
+
status = error?.status;
|
|
610
|
+
statusText = error?.statusText;
|
|
611
|
+
}
|
|
612
|
+
|
|
589
613
|
const errorToThrow = this.createError(
|
|
590
|
-
|
|
614
|
+
errorCode,
|
|
591
615
|
errorMessage,
|
|
592
616
|
{
|
|
593
|
-
status
|
|
594
|
-
statusText
|
|
617
|
+
status,
|
|
618
|
+
statusText,
|
|
595
619
|
errorData: error?.errorData,
|
|
596
620
|
originalError: error?.message
|
|
597
621
|
}
|