diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 0e11e2bf11..207e0dcdd9 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -47,7 +47,8 @@ [status-im.components.status :as status] [status-im.components.styles :as st] [status-im.chat.styles.screen :as chat-st] - [status-im.profile.qr-code.screen :refer [qr-code-view]])) + [status-im.profile.qr-code.screen :refer [qr-code-view]] + [status-im.utils.utils :as utils])) (defn init-back-button-handler! [] (let [new-listener (fn [] @@ -166,6 +167,7 @@ [component])]])]]))))}))) (defn init [] + (utils/register-exception-handler) (status/call-module status/init-jail) (dispatch-sync [:reset-app]) (.registerComponent app-registry "StatusIm" #(r/reactify-component app-root)) diff --git a/src/status_im/ios/core.cljs b/src/status_im/ios/core.cljs index 61d1f0e734..2e543eb868 100644 --- a/src/status_im/ios/core.cljs +++ b/src/status_im/ios/core.cljs @@ -43,7 +43,8 @@ [taoensso.timbre :as log] [status-im.chat.styles.screen :as st] [status-im.profile.qr-code.screen :refer [qr-code-view]] - [status-im.components.status :as status])) + [status-im.components.status :as status] + [status-im.utils.utils :as utils])) (defn orientation->keyword [o] (keyword (.toLowerCase o))) @@ -137,6 +138,7 @@ [component])]])]))))}))) (defn init [] + (utils/register-exception-handler) (status/call-module status/init-jail) (dispatch-sync [:reset-app]) (dispatch [:listen-to-network-status!]) diff --git a/src/status_im/utils/utils.cljs b/src/status_im/utils/utils.cljs index d107363d23..064d06eb29 100644 --- a/src/status_im/utils/utils.cljs +++ b/src/status_im/utils/utils.cljs @@ -116,3 +116,16 @@ (apply update m k f args) m)) +(defn default-alert-handler + [error fatal?] + (show-popup "Error" (.-message error))) + +(defn register-exception-handler + "Register a function that will be called for each exception thrown. + When `dev?` is true, always register; otherwise only register when goog.DEBUG is false. + Default function shows error details in an alert box." + ([] (register-exception-handler default-alert-handler)) + ([f] (register-exception-handler true f)) + ([dev? f] + (if (or dev? (not js/goog.DEBUG)) + (.setGlobalHandler js/ErrorUtils f dev?))))