SelfLender / react-native-biometrics

React Native module for iOS and Android biometrics
MIT License
653 stars 222 forks source link

Can we have proper error codes in failure scenarios instead of the error strings #198

Open vinaykaitha opened 2 years ago

vinaykaitha commented 2 years ago

Like in this case:

    @Override
    public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
        super.onAuthenticationError(errorCode, errString);
        if (errorCode == BiometricPrompt.ERROR_NEGATIVE_BUTTON || errorCode == BiometricPrompt.ERROR_USER_CANCELED ) {
            WritableMap resultMap = new WritableNativeMap();
            resultMap.putBoolean("success", false);
            resultMap.putString("error", "User cancellation");
            this.promise.resolve(resultMap);
        } else {
            this.promise.reject(errString.toString(), errString.toString());
        }
    }

this.promise.reject(errorCode.toString(), errString.toString()); and

WritableMap resultMap = new WritableNativeMap();
resultMap.putBoolean("success", false);
resultMap.putString("errorCode", errorCode.toString());
this.promise.resolve(resultMap);

would have been more helpful.

So that we can show specific message to the user, like "You haven't enrolled for biometric on this device" etc.. Same goes for iOS.

UraFIZ commented 2 years ago

This is a great idea to organize error messages in this project.

jayfunk commented 2 years ago

Gladly would accept a PR.