-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error instanceof BiometryError, error.code typing #20
Comments
The error thrown by any Capacitor plugin is actually an instance of Even if I intercept the exception and throw a interface TypedBiometryError extends BiometryError {
code: BiometryErrorType
}
async function showErrorAlert(error: TypedBiometryError): Promise<void> {
await showAlert(`${error.message} [${error.code}].`);
}
function isBiometryError(error: unknown): error is TypedBiometryError {
return error instanceof CapacitorException;
}
function isBiometryError(error: unknown): error is TypedBiometryError {
return error instanceof CapacitorException;
}
async function authenticate(): Promise<void> {
try {
await BiometricAuth.authenticate({
allowDeviceCredential: true,
});
} catch (error) {
// The type guard will ensure you compare error.code against a valid BiometryErrorType value
if (isBiometryError(error) && error.code === BiometryErrorType.biometryNotEnrolled) {
showAlert(error)
}
throw error;
}
} |
In any case I should add that type guard function to the plugin and type |
Thanks for the request, v6.0.0 has just been released that throws an instance of |
For developer experience with typescript, I want to do
error instanceof BiometryError
like the following:Because
error instanceof BiometryError
evaluates to false, I have to do the following:or I have to unsafely cast.
Also,
BiometryError.code
is typed as string, it would be nice if it was BiometryErrorType.Thank you!
The text was updated successfully, but these errors were encountered: