From ad30f7ef8117e8a6b486edfd531a6004c2801e52 Mon Sep 17 00:00:00 2001 From: Lungu Cristian Date: Fri, 19 Jan 2024 11:43:34 +0200 Subject: [PATCH] ref: using ex-cause for biometric error codes --- src/react_native/biometrics.cljs | 21 ++++++++++--------- src/status_im/common/biometric/events.cljs | 7 ++++--- .../standard_auth/authorize.cljs | 4 +++- .../contexts/profile/login/events.cljs | 10 ++++++--- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/react_native/biometrics.cljs b/src/react_native/biometrics.cljs index db12a97462ee..0e46c6eaa796 100644 --- a/src/react_native/biometrics.cljs +++ b/src/react_native/biometrics.cljs @@ -37,17 +37,18 @@ ;; On android we get error messages while on iOS it's a stringified Obj-C error object. (defn- convert-auth-error-message [message] - (ex-info "Failed to authenticate with biometrics" - {:orig-error-message message - :code (if platform/android? - (condp = message - android-not-enrolled-error-message ::not-enrolled - android-not-available-error-message ::not-available - ::unknown) + (let [cause (if platform/android? + (condp = message + android-not-enrolled-error-message ::not-enrolled + android-not-available-error-message ::not-available + ::unknown) - (condp #(string/includes? %2 %1) message - ios-not-enrolled-error-message ::not-enrolled - ::unknown))})) + (condp #(string/includes? %2 %1) message + ios-not-enrolled-error-message ::not-enrolled + ::unknown))] + (ex-info "Failed to authenticate with biometrics" + {:orig-error-message message} + cause))) (defn authenticate "Returns a JS promise that resolves with a boolean auth success state: `true` for diff --git a/src/status_im/common/biometric/events.cljs b/src/status_im/common/biometric/events.cljs index 705ee59897c9..ab2c3a5d9372 100644 --- a/src/status_im/common/biometric/events.cljs +++ b/src/status_im/common/biometric/events.cljs @@ -44,8 +44,9 @@ (rf/defn show-message {:events [:biometric/show-message]} - [_ code] - (let [content (if (#{::biometrics/not-enrolled + [_ error] + (let [code (ex-cause error) + content (if (#{::biometrics/not-enrolled ::biometrics/not-available} code) (i18n/label :t/grant-face-id-permissions) @@ -68,7 +69,7 @@ (on-success)))) (.catch (fn [err] (when on-fail - (-> err ex-data :code on-fail))))))) + (on-fail err))))))) (rf/defn authenticate {:events [:biometric/authenticate]} diff --git a/src/status_im/common/standard_authentication/standard_auth/authorize.cljs b/src/status_im/common/standard_authentication/standard_auth/authorize.cljs index 53198fda283f..6193fec476c6 100644 --- a/src/status_im/common/standard_authentication/standard_auth/authorize.cljs +++ b/src/status_im/common/standard_authentication/standard_auth/authorize.cljs @@ -49,7 +49,9 @@ (handle-auth-success true)]))) :on-fail (fn [error] (on-close) - (log/error "Authentication Failed. Error:" error) + (log/error + (ex-message error) + (-> error ex-data (assoc :code (ex-cause error)))) (when on-auth-fail (on-auth-fail error)) (password-login {:on-press-biometrics #(on-press-biometrics diff --git a/src/status_im/contexts/profile/login/events.cljs b/src/status_im/contexts/profile/login/events.cljs index c1dd2bbd34b5..aad293b40709 100644 --- a/src/status_im/contexts/profile/login/events.cljs +++ b/src/status_im/contexts/profile/login/events.cljs @@ -212,9 +212,13 @@ (rf/reg-event-fx :profile.login/biometric-auth-fail - (fn [_ [code]] - {:dispatch [:biometric/show-message code]})) - + (fn [_ [error]] + (log/error (ex-message error) + (-> error + ex-data + (assoc :code (ex-cause error) + :event :profile.login/biometric-auth-fail))) + {:dispatch [:biometric/show-message error]})) (rf/defn verify-database-password {:events [:profile.login/verify-database-password]}