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