Added logging, and, hopefully, visible error messages.
This commit is contained in:
parent
aff1e90ceb
commit
cafecd0296
|
@ -1,8 +1,9 @@
|
|||
(ns ireadit.routes.services
|
||||
(:require [ring.util.http-response :refer :all]
|
||||
[cemerick.url :refer (url-decode)]
|
||||
(:require [cemerick.url :refer (url-decode)]
|
||||
[clojure.tools.logging :as log]
|
||||
[compojure.api.sweet :refer :all]
|
||||
[ireadit.tesseractor :refer [ocr]]
|
||||
[ring.util.http-response :refer :all]
|
||||
[schema.core :as s]))
|
||||
|
||||
(def service-routes
|
||||
|
@ -19,4 +20,7 @@
|
|||
(POST "/ocr/:uri" []
|
||||
:return String
|
||||
:path-params [uri :- String]
|
||||
(ok (ocr (url-decode uri)))))))
|
||||
(ok (let [decoded (url-decode uri)
|
||||
text (ocr decoded)]
|
||||
(log/info (str "ocr '" decoded "' => '" text "'"))
|
||||
text))))))
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
:response-format (ajax/json-response-format)
|
||||
:on-success [:set-transcription]
|
||||
:on-failure [:bad-transcription]}
|
||||
:db (assoc (dissoc (dissoc db :transcription) :common/error) :pending true)})))
|
||||
:db (assoc (dissoc db :transcription :common/error :error) :pending true)})))
|
||||
|
||||
(rf/reg-event-db
|
||||
:set-transcription
|
||||
|
@ -49,18 +49,18 @@
|
|||
(js/console.log (str "Failed to fetch transcription data" response))
|
||||
(dissoc (assoc db :transcription response) :pending)))
|
||||
|
||||
(rf/reg-event-fx
|
||||
(rf/reg-event-db
|
||||
:bad-transcription
|
||||
(fn
|
||||
[{db :db} [_ response]]
|
||||
[db [_ response]]
|
||||
;; TODO: signal something has failed? It doesn't matter very much, unless it keeps failing.
|
||||
(js/console.log (str "Failed to fetch transcription data" response))
|
||||
(dissoc (assoc db :common/error response) :pending)))
|
||||
(dissoc (assoc db :error response) :pending)))
|
||||
|
||||
(rf/reg-event-db
|
||||
:common/set-error
|
||||
(fn [db [_ error]]
|
||||
(assoc db :common/error error)))
|
||||
(assoc (assoc db :common/error error) :error error)))
|
||||
|
||||
;;subscriptions
|
||||
|
||||
|
@ -79,6 +79,11 @@
|
|||
(fn [db _]
|
||||
(:common/error db)))
|
||||
|
||||
(rf/reg-sub
|
||||
:error
|
||||
(fn [db _]
|
||||
(:error db)))
|
||||
|
||||
(rf/reg-sub
|
||||
:url
|
||||
(fn [db _]
|
||||
|
|
|
@ -39,6 +39,6 @@
|
|||
[:div.col-sm-12 {:class (if @(rf/subscribe [:transcription]) "visible" "hidden")}
|
||||
[b/Alert {:color "success"} @(rf/subscribe [:transcription])]]]
|
||||
[b/Row
|
||||
[:div.col-sm-12 {:class (if @(rf/subscribe [:common/error]) "visible" "hidden")}
|
||||
[b/Alert {:color "warning"} @(rf/subscribe [:common/error])]]]]])
|
||||
[:div.col-sm-12 {:class (if @(rf/subscribe [:error]) "visible" "hidden")}
|
||||
[b/Alert {:color "warning"} @(rf/subscribe [:error])]]]]])
|
||||
|
||||
|
|
Loading…
Reference in a new issue