Skip to content

Commit

Permalink
ref: using ex-cause for biometric error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
clauxx committed Jan 19, 2024
1 parent 226903c commit ad30f7e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
21 changes: 11 additions & 10 deletions src/react_native/biometrics.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/status_im/common/biometric/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/status_im/contexts/profile/login/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]}
Expand Down

0 comments on commit ad30f7e

Please sign in to comment.