handle errors from jail

This commit is contained in:
Roman Volosovskyi 2016-06-23 19:07:31 +03:00
parent d07688136f
commit 40dd0063d2
4 changed files with 39 additions and 24 deletions

View File

@ -133,7 +133,7 @@ dependencies {
compile project(':react-native-camera') compile project(':react-native-camera')
compile project(':react-native-status') compile project(':react-native-status')
compile project(':react-native-orientation') compile project(':react-native-orientation')
compile(group: 'status-im', name: 'status-go', version: '0.1.0-201606220917-ec4b9a', ext: 'aar') compile(group: 'status-im', name: 'status-go', version: '0.1.0-201606231357-85abe1', ext: 'aar')
compile fileTree(dir: "node_modules/realm/android/libs", include: ["*.jar"]) compile fileTree(dir: "node_modules/realm/android/libs", include: ["*.jar"])
} }

View File

@ -85,7 +85,9 @@
(defn container-animation-logic [{:keys [to-value val]}] (defn container-animation-logic [{:keys [to-value val]}]
(fn [_] (fn [_]
(let [to-value @to-value] (let [to-value @to-value]
(anim/start (anim/spring val {:toValue to-value}))))) (anim/start (anim/spring val {:toValue to-value
:tension 50
:friction 10})))))
(defn container [response-height & children] (defn container [response-height & children]
(let [;; todo to-response-height, cur-response-height must be specific (let [;; todo to-response-height, cur-response-height must be specific

View File

@ -26,19 +26,30 @@
(def regular-events {}) (def regular-events {})
(defn command-nadler! (defn print-error! [error]
[_ [{:keys [to]} response]] (toast error)
(let [{:keys [event params]} (json->cljs response) (println error))
events (if (= "console" to)
(merge regular-events console-events)
regular-events)]
(when-let [handler (events (keyword event))]
(apply handler params))))
(defn suggestions-handler (defn command-hadler!
[_ [{:keys [to] :as command} response]]
(let [{:keys [error result]} (json->cljs response)]
(if error
(let [m (str "Error on command handling!\n" command error)]
(print-error! m))
(let [{:keys [event params]} result
events (if (= "console" to)
(merge regular-events console-events)
regular-events)]
(when-let [handler (events (keyword event))]
(apply handler params))))))
(defn suggestions-handler!
[db [{:keys [chat-id]} response-json]] [db [{:keys [chat-id]} response-json]]
(let [response (json->cljs response-json)] (let [{:keys [error result]} (json->cljs response-json)]
(assoc-in db [:suggestions chat-id] (generate-hiccup response)))) (when error
(let [m (str "Error on param suggestions!\n" error)]
(print-error! m)))
(assoc-in db [:suggestions chat-id] (generate-hiccup result))))
(defn suggestions-events-handler! (defn suggestions-events-handler!
[db [[n data]]] [db [[n data]]]
@ -62,9 +73,9 @@
(reg-handler :init-render-command! init-render-command!) (reg-handler :init-render-command! init-render-command!)
(reg-handler ::render-command render-command) (reg-handler ::render-command render-command)
(reg-handler :command-handler! (u/side-effect! command-nadler!)) (reg-handler :command-handler! (u/side-effect! command-hadler!))
(reg-handler :suggestions-handler (reg-handler :suggestions-handler
(after #(dispatch [:animate-show-response])) (after #(dispatch [:animate-show-response]))
suggestions-handler) suggestions-handler!)
(reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!)) (reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!))
(reg-handler :command-preview command-preview) (reg-handler :command-preview command-preview)

View File

@ -44,10 +44,10 @@
(defn parse-commands! [_ [identity file]] (defn parse-commands! [_ [identity file]]
(j/parse identity file (j/parse identity file
(fn [result] (fn [result]
(let [commands (json->cljs result)] (let [{:keys [error result]} (json->cljs result)]
;; todo use commands from jail (if error
(dispatch [::add-commands identity file commands]))) (dispatch [::loading-failed! identity ::error-in-jail error])
#_(dispatch [::loading-failed! identity ::error-in-jail %]))) (dispatch [::add-commands identity file result]))))))
(defn validate-hash (defn validate-hash
[db [identity file]] [db [identity file]]
@ -70,11 +70,13 @@
(defn loading-failed! (defn loading-failed!
[db [id reason details]] [db [id reason details]]
(let [url (get-in db [:chats id :dapp-url])] (let [url (get-in db [:chats id :dapp-url])]
(toast (s/join "\n" ["commands.js loading failed" (let [m (s/join "\n" ["commands.js loading failed"
url url
id id
(name reason) (name reason)
details])))) details])]
(toast m)
(println m))))
(reg-handler :load-commands! (u/side-effect! load-commands!)) (reg-handler :load-commands! (u/side-effect! load-commands!))
(reg-handler ::fetch-commands! (u/side-effect! fetch-commands!)) (reg-handler ::fetch-commands! (u/side-effect! fetch-commands!))