parsePlatformException function
Parses a PlatformException thrown by the platform channel and converts it into a SecureBiometricAuthException if possible.
Returns the original exception if it cannot be mapped.
Implementation
Exception parsePlatformException(Exception e) {
if (e is PlatformException) {
switch (e.code) {
case 'DEVICE_NOT_SUPPORTED':
return SecureBiometricAuthException(
SecureBiometricAuthErrorType.deviceNotSupported,
e.message,
);
case 'INVALID_ARGUMENTS':
return SecureBiometricAuthException(
SecureBiometricAuthErrorType.invalidArguments,
e.message,
);
case 'PRIVATE_KEY_IS_NOT_EXIST':
return SecureBiometricAuthException(
SecureBiometricAuthErrorType.privateKeyIsNotExist,
e.message,
);
case 'USER_CANCEL':
return SecureBiometricAuthException(
SecureBiometricAuthErrorType.userCancel,
e.message,
);
case 'CANCEL':
return SecureBiometricAuthException(
SecureBiometricAuthErrorType.cancel,
e.message,
);
case 'BIOMETRIC_AUTH_FAILED':
return SecureBiometricAuthException(
SecureBiometricAuthErrorType.biometricAuthFailed,
e.message,
);
case 'BIOMETRIC_INVALID_CREDENTIAL':
return SecureBiometricAuthException(
SecureBiometricAuthErrorType.biometricInvalidCredential,
e.message,
);
case 'BIOMETRIC_NONE_ENROLLED':
return SecureBiometricAuthException(
SecureBiometricAuthErrorType.biometricNoneEnrolled,
e.message,
);
case 'BIOMETRIC_LOCKOUT':
return SecureBiometricAuthException(
SecureBiometricAuthErrorType.biometricLockout,
e.message,
);
case 'UNKNOWN_ERROR':
return SecureBiometricAuthException(
SecureBiometricAuthErrorType.unknown,
e.message,
);
default:
return e;
}
}
return e;
}