mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-06 18:33:38 +02:00
Add user notifications and display api errors (#10)
Closes #2 * Add user notifications * Update re-frame-10x config * Display api errors as notifications * Automatically hide notifications after a while
This commit is contained in:
parent
187f001414
commit
ab7519f289
12 changed files with 232 additions and 42 deletions
|
|
@ -14,12 +14,13 @@
|
||||||
;; for CIDER
|
;; for CIDER
|
||||||
[cider/cider-nrepl "0.18.0-SNAPSHOT"]]
|
[cider/cider-nrepl "0.18.0-SNAPSHOT"]]
|
||||||
|
|
||||||
|
:nrepl {:port 9000}
|
||||||
|
|
||||||
:builds
|
:builds
|
||||||
{:app {:target :browser
|
{:app {:target :browser
|
||||||
:output-dir "public/app/js"
|
:output-dir "public/app/js"
|
||||||
:asset-path "/app/js"
|
:asset-path "/app/js"
|
||||||
:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true
|
:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true}
|
||||||
"day8.re_frame.tracing.trace_enabled_QMARK_" true}
|
|
||||||
:modules {:main {:entries [airsonic-ui.core]}}
|
:modules {:main {:entries [airsonic-ui.core]}}
|
||||||
:devtools {:http-root "public"
|
:devtools {:http-root "public"
|
||||||
:http-port 8080
|
:http-port 8080
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,5 @@
|
||||||
|
|
||||||
(def default-db
|
(def default-db
|
||||||
{;; because navigate! executes asynchronously we force to display the login screen first
|
{;; because navigate! executes asynchronously we force to display the login screen first
|
||||||
:current-route [routes/default-route]})
|
:current-route [routes/default-route]
|
||||||
|
:notifications (sorted-map)})
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,12 @@
|
||||||
;; ::events/something-happening -> relevant to only this app
|
;; ::events/something-happening -> relevant to only this app
|
||||||
;; :single-colon/something -> coming from external sources (e.g. :audio/... or :routes/...) that are potentially reusable
|
;; :single-colon/something -> coming from external sources (e.g. :audio/... or :routes/...) that are potentially reusable
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
;; a simple effect to keep println statements out of our event handlers
|
||||||
|
:log
|
||||||
|
(fn [params]
|
||||||
|
(apply println params)))
|
||||||
|
|
||||||
;; database reset / init
|
;; database reset / init
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
|
|
@ -29,12 +35,24 @@
|
||||||
:http-xhrio {:method :get
|
:http-xhrio {:method :get
|
||||||
:uri (api/url server "ping" {:u user :p pass})
|
:uri (api/url server "ping" {:u user :p pass})
|
||||||
:response-format (ajax/json-response-format {:keywords? true})
|
:response-format (ajax/json-response-format {:keywords? true})
|
||||||
:on-success [::credentials-verified user pass]
|
:on-success [::verify-auth-response user pass]
|
||||||
:on-failure [::api-failure]}})
|
:on-failure [:api/bad-response]}})
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::authenticate authenticate)
|
::authenticate authenticate)
|
||||||
|
|
||||||
|
(defn verify-auth-response
|
||||||
|
"Since we don't get real status codes, we have to look into the server's
|
||||||
|
response and see whether we actually sent the correct credentials"
|
||||||
|
[fx [_ user pass response]]
|
||||||
|
{:dispatch (if (api/is-error? response)
|
||||||
|
[:notification/show :error (api/error-msg (api/->exception response))]
|
||||||
|
[::credentials-verified user pass])})
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::verify-auth-response
|
||||||
|
verify-auth-response)
|
||||||
|
|
||||||
(defn try-remember-user
|
(defn try-remember-user
|
||||||
"Enables skipping the auth request when credentials are saved in the
|
"Enables skipping the auth request when credentials are saved in the
|
||||||
local storage; otherwise has no effect"
|
local storage; otherwise has no effect"
|
||||||
|
|
@ -51,7 +69,7 @@
|
||||||
(defn credentials-verified
|
(defn credentials-verified
|
||||||
"Gets called after the server indicates that the credentials entered by a user
|
"Gets called after the server indicates that the credentials entered by a user
|
||||||
are correct (see `authenticate`)"
|
are correct (see `authenticate`)"
|
||||||
[{:keys [db store]} [_event user pass _response]]
|
[{:keys [db store]} [_ user pass]]
|
||||||
(let [auth {:u user :p pass}
|
(let [auth {:u user :p pass}
|
||||||
credentials (merge (:credentials db) auth)]
|
credentials (merge (:credentials db) auth)]
|
||||||
{:routes/set-credentials auth
|
{:routes/set-credentials auth
|
||||||
|
|
@ -87,26 +105,32 @@
|
||||||
(let [creds (:credentials db)]
|
(let [creds (:credentials db)]
|
||||||
(api/url (:server creds) endpoint (merge params (select-keys creds [:u :p])))))
|
(api/url (:server creds) endpoint (merge params (select-keys creds [:u :p])))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(defn api-request [{:keys [db]} [_ endpoint params]]
|
||||||
:api-request
|
|
||||||
(fn [{:keys [db]} [_ endpoint k params]]
|
|
||||||
{:http-xhrio {:method :get
|
{:http-xhrio {:method :get
|
||||||
:uri (api-url db endpoint params)
|
:uri (api-url db endpoint params)
|
||||||
:response-format (ajax/json-response-format {:keywords? true})
|
:response-format (ajax/json-response-format {:keywords? true})
|
||||||
:on-success [::api-success k]
|
:on-success [:api/good-response]
|
||||||
:on-failure [::api-failure]}}))
|
:on-failure [:api/bad-response]}})
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-fx
|
||||||
::api-success
|
:api/request
|
||||||
(fn [db [_ k response]]
|
api-request)
|
||||||
; we "unwrap" the responses
|
|
||||||
(assoc db :response (-> response :subsonic-response k))))
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(defn good-api-response [fx [_ response]]
|
||||||
::api-failure
|
(try
|
||||||
|
(assoc-in fx [:db :response] (api/unwrap-response response))
|
||||||
|
(catch ExceptionInfo e
|
||||||
|
{:dispatch [:notification/show :error (api/error-msg e)]})))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
:api/good-response
|
||||||
|
good-api-response)
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
:api/bad-response
|
||||||
(fn [db event]
|
(fn [db event]
|
||||||
(println "api call gone bad; CORS headers missing? check for :status 0" event)
|
{:log ["API call gone bad; are CORS headers missing? check for :status 0" event]
|
||||||
db))
|
:dispatch [:notification/show :error "Communication with server failed. Check browser logs for details."]}))
|
||||||
|
|
||||||
;; musique
|
;; musique
|
||||||
|
|
||||||
|
|
@ -173,3 +197,38 @@
|
||||||
{:routes/navigate [routes/default-route]
|
{:routes/navigate [routes/default-route]
|
||||||
:routes/unset-credentials nil
|
:routes/unset-credentials nil
|
||||||
:db db/default-db}))
|
:db db/default-db}))
|
||||||
|
|
||||||
|
;; user messages
|
||||||
|
|
||||||
|
(def notification-duration
|
||||||
|
{:info 2500
|
||||||
|
:error 10000})
|
||||||
|
|
||||||
|
(defn show-notification
|
||||||
|
"Displays an informative message to the user"
|
||||||
|
[fx [_ level message]]
|
||||||
|
(let [id (.now js/performance)
|
||||||
|
hide-later (fn [level]
|
||||||
|
[{:ms (get notification-duration level)
|
||||||
|
:dispatch [:notification/hide id]}])]
|
||||||
|
(if (nil? message)
|
||||||
|
(let [message level
|
||||||
|
level :info]
|
||||||
|
(-> (assoc-in fx [:db :notifications id] {:level level
|
||||||
|
:message message})
|
||||||
|
(assoc :dispatch-later (hide-later level))))
|
||||||
|
(-> (assoc-in fx [:db :notifications id] {:level level
|
||||||
|
:message message})
|
||||||
|
(assoc :dispatch-later (hide-later level))))))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
:notification/show
|
||||||
|
show-notification)
|
||||||
|
|
||||||
|
(defn hide-notification
|
||||||
|
[db [_ notification-id]]
|
||||||
|
(update db :notifications dissoc notification-id))
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
:notification/hide
|
||||||
|
hide-notification)
|
||||||
|
|
|
||||||
|
|
@ -28,16 +28,16 @@
|
||||||
|
|
||||||
(defmethod route-data ::main
|
(defmethod route-data ::main
|
||||||
[route-id params query]
|
[route-id params query]
|
||||||
[:api-request "getAlbumList2" :albumList2 {:type "recent"
|
[:api/request "getAlbumList2" {:type "recent"
|
||||||
:size 18}])
|
:size 18}])
|
||||||
|
|
||||||
(defmethod route-data ::artist-view
|
(defmethod route-data ::artist-view
|
||||||
[route-id params query]
|
[route-id params query]
|
||||||
[:api-request "getArtist" :artist (select-keys params [:id])])
|
[:api/request "getArtist" (select-keys params [:id])])
|
||||||
|
|
||||||
(defmethod route-data ::album-view
|
(defmethod route-data ::album-view
|
||||||
[route-id params query]
|
[route-id params query]
|
||||||
[:api-request "getAlbum" :album (select-keys params [:id])])
|
[:api/request "getAlbum" (select-keys params [:id])])
|
||||||
|
|
||||||
;; shouldn't need to change anything below
|
;; shouldn't need to change anything below
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,40 +6,38 @@
|
||||||
;; FIXME: this is used for cover images and it's quite ugly tbh
|
;; FIXME: this is used for cover images and it's quite ugly tbh
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::login
|
::login
|
||||||
(fn [db]
|
(fn [db _]
|
||||||
(select-keys (:credentials db) [:u :p])))
|
(select-keys (:credentials db) [:u :p])))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::user
|
::user
|
||||||
(fn [{:keys [credentials]}]
|
(fn [{:keys [credentials]} [_]]
|
||||||
{:name (:u credentials)}))
|
{:name (:u credentials)}))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::server
|
::server
|
||||||
(fn [db]
|
(fn [db _]
|
||||||
(get-in db [:credentials :server])))
|
(get-in db [:credentials :server])))
|
||||||
|
|
||||||
;; current hashbang
|
;; current hashbang
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::current-route
|
::current-route
|
||||||
(fn [db]
|
(fn [db _]
|
||||||
(:current-route db)))
|
(:current-route db)))
|
||||||
|
|
||||||
;; ---
|
|
||||||
|
|
||||||
;; TODO: Make this nice and clean
|
;; TODO: Make this nice and clean
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::current-content
|
::current-content
|
||||||
(fn [db]
|
(fn [db _]
|
||||||
(db :response)))
|
(:response db)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
; returns info on the current song as is (basically the metadata you can read from the file system)
|
; returns info on the current song as is (basically the metadata you can read from the file system)
|
||||||
::currently-playing
|
::currently-playing
|
||||||
(fn [db]
|
(fn [db _]
|
||||||
(db :currently-playing)))
|
(:currently-playing db)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::is-playing?
|
::is-playing?
|
||||||
|
|
@ -49,3 +47,10 @@
|
||||||
(let [status (:status currently-playing)]
|
(let [status (:status currently-playing)]
|
||||||
(and (not (:paused? status))
|
(and (not (:paused? status))
|
||||||
(not (:ended? status))))))
|
(not (:ended? status))))))
|
||||||
|
|
||||||
|
;; user notifications
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::notifications
|
||||||
|
(fn [db _]
|
||||||
|
(:notifications db)))
|
||||||
|
|
|
||||||
|
|
@ -22,3 +22,31 @@
|
||||||
|
|
||||||
(defn cover-url [server credentials item size]
|
(defn cover-url [server credentials item size]
|
||||||
(url server "getCoverArt" (merge {:id (:coverArt item) :size size} credentials)))
|
(url server "getCoverArt" (merge {:id (:coverArt item) :size size} credentials)))
|
||||||
|
|
||||||
|
(defn is-error? [response]
|
||||||
|
(= "failed" (get-in response [:subsonic-response :status])))
|
||||||
|
|
||||||
|
(defn- unwrap-response* [response]
|
||||||
|
(-> (:subsonic-response response)
|
||||||
|
(dissoc :status :version)
|
||||||
|
vals
|
||||||
|
first))
|
||||||
|
|
||||||
|
(defn ->exception
|
||||||
|
"Takes an erroneous response and makes it a real exception"
|
||||||
|
[response]
|
||||||
|
(let [error (unwrap-response* response)]
|
||||||
|
(ex-info (:message response) error)))
|
||||||
|
|
||||||
|
(defn unwrap-response
|
||||||
|
"Retrieves the actual response body"
|
||||||
|
[response]
|
||||||
|
(if (is-error? response)
|
||||||
|
(let [error (:error response)]
|
||||||
|
(throw (->exception response)))
|
||||||
|
(unwrap-response* response)))
|
||||||
|
|
||||||
|
(defn error-msg
|
||||||
|
[exception-info]
|
||||||
|
(let [{:keys [code message]} (ex-data exception-info)]
|
||||||
|
(str "Error " code ": " message)))
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
[airsonic-ui.events :as events]
|
[airsonic-ui.events :as events]
|
||||||
[airsonic-ui.subs :as subs]
|
[airsonic-ui.subs :as subs]
|
||||||
|
|
||||||
|
[airsonic-ui.views.notifications :refer [notification-list]]
|
||||||
[airsonic-ui.views.breadcrumbs :refer [breadcrumbs]]
|
[airsonic-ui.views.breadcrumbs :refer [breadcrumbs]]
|
||||||
[airsonic-ui.views.bottom-bar :refer [bottom-bar]]
|
[airsonic-ui.views.bottom-bar :refer [bottom-bar]]
|
||||||
[airsonic-ui.views.login :refer [login-form]]
|
[airsonic-ui.views.login :refer [login-form]]
|
||||||
|
|
@ -65,7 +66,10 @@
|
||||||
[bottom-bar]]))
|
[bottom-bar]]))
|
||||||
|
|
||||||
(defn main-panel []
|
(defn main-panel []
|
||||||
(let [[route params query] @(subscribe [::subs/current-route])]
|
(let [[route params query] @(subscribe [::subs/current-route])
|
||||||
|
notifications @(subscribe [::subs/notifications])]
|
||||||
|
[:div
|
||||||
|
[notification-list notifications]
|
||||||
(case route
|
(case route
|
||||||
::routes/login [login-form]
|
::routes/login [login-form]
|
||||||
[app route params query])))
|
[app route params query])]))
|
||||||
|
|
|
||||||
14
src/cljs/airsonic_ui/views/notifications.cljs
Normal file
14
src/cljs/airsonic_ui/views/notifications.cljs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
(ns airsonic-ui.views.notifications
|
||||||
|
(:require [re-frame.core :refer [dispatch]]))
|
||||||
|
|
||||||
|
;; user notifications
|
||||||
|
|
||||||
|
(defn notification-list [notifications]
|
||||||
|
[:div.notifications
|
||||||
|
(for [[id notification] notifications]
|
||||||
|
(let [class (case (:level notification)
|
||||||
|
:error "danger"
|
||||||
|
"info")]
|
||||||
|
^{:key id} [:div {:class-name (str "notification is-small is-" class)}
|
||||||
|
[:button.delete {:on-click #(dispatch [:notification/hide id])}]
|
||||||
|
(:message notification)]))])
|
||||||
|
|
@ -73,3 +73,12 @@
|
||||||
.table
|
.table
|
||||||
.grow
|
.grow
|
||||||
width: 100%
|
width: 100%
|
||||||
|
|
||||||
|
// floating notifications
|
||||||
|
.notifications
|
||||||
|
@extend .container
|
||||||
|
z-index: 100
|
||||||
|
position: fixed
|
||||||
|
left: 0
|
||||||
|
right: 0
|
||||||
|
padding-top: 3.2rem
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
(ns airsonic-ui.events-test
|
(ns airsonic-ui.events-test
|
||||||
(:require [cljs.test :refer [deftest testing is]]
|
(:require [cljs.test :refer [deftest testing is]]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
|
[airsonic-ui.fixtures :refer [responses]]
|
||||||
[airsonic-ui.events :as events]))
|
[airsonic-ui.events :as events]))
|
||||||
|
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
|
|
@ -16,8 +17,14 @@
|
||||||
(testing "saves the given server location"
|
(testing "saves the given server location"
|
||||||
(is (= server (get-in fx [:db :credentials :server]))))
|
(is (= server (get-in fx [:db :credentials :server]))))
|
||||||
(testing "invokes correct success callback"
|
(testing "invokes correct success callback"
|
||||||
(is (= ::events/credentials-verified (first (:on-success request)))))))
|
(is (= ::events/verify-auth-response (first (:on-success request)))))))
|
||||||
(testing "On succesfull response"
|
(testing "Auth response verification"
|
||||||
|
(is (= :notification/show
|
||||||
|
(first (:dispatch (events/verify-auth-response {} [:_ "user" "pass" (:error responses)]))))
|
||||||
|
"shows an error when we have an error response")
|
||||||
|
(let [event (:dispatch (events/verify-auth-response {} [:_ "username" "password" (:auth-success responses)]))]
|
||||||
|
(is (= [::events/credentials-verified "username" "password"] event))))
|
||||||
|
(testing "On succesful response"
|
||||||
(let [creds-before {:server "https://localhost"}
|
(let [creds-before {:server "https://localhost"}
|
||||||
fx (events/credentials-verified {:db {:credentials creds-before}}
|
fx (events/credentials-verified {:db {:credentials creds-before}}
|
||||||
[:_ "user" "pass"])
|
[:_ "user" "pass"])
|
||||||
|
|
@ -43,3 +50,34 @@
|
||||||
(testing "When there's no previous login data"
|
(testing "When there's no previous login data"
|
||||||
(testing "remembering has no effect"
|
(testing "remembering has no effect"
|
||||||
(is (nil? (events/try-remember-user {} [:_]))))))
|
(is (nil? (events/try-remember-user {} [:_]))))))
|
||||||
|
|
||||||
|
(defn- first-notification [fx]
|
||||||
|
(-> (get-in fx [:db :notifications]) vals first))
|
||||||
|
|
||||||
|
(deftest api-interaction
|
||||||
|
(testing "Should show an error notification when airsonic responds with an error"
|
||||||
|
(let [fx (events/good-api-response {} [:_ (:error responses)])]
|
||||||
|
(is (= :error (-> fx :dispatch second))))))
|
||||||
|
|
||||||
|
(deftest user-notifications
|
||||||
|
(testing "Should be able to display a message with an assigned level"
|
||||||
|
(is (= :error (:level (first-notification (events/show-notification {} [:_ :error "foo"])))))
|
||||||
|
(is (= :info (:level (first-notification (events/show-notification {} [:_ :info "some other message"]))))))
|
||||||
|
(testing "Should default to level :info"
|
||||||
|
(is (= :info (:level (first-notification (events/show-notification {} [:_ "and another one"]))))))
|
||||||
|
(testing "Should create a unique id for each message"
|
||||||
|
(let [state (->
|
||||||
|
{}
|
||||||
|
(events/show-notification [:_ :info "Something something"])
|
||||||
|
(events/show-notification [:_ :error "Something important"]))
|
||||||
|
ids (keys (:notifications state))]
|
||||||
|
(is (= (count ids) (count (set ids))))))
|
||||||
|
(testing "Should remove a message, given it's id"
|
||||||
|
(let [state (events/show-notification {} [:_ "This is a notification"])
|
||||||
|
id (-> (:notifications state)
|
||||||
|
keys
|
||||||
|
first)]
|
||||||
|
(is (empty? (:notifications (events/hide-notification state [:_ id]))))))
|
||||||
|
(testing "Should automatically remove a message after a while"
|
||||||
|
(let [fx (events/show-notification {} [:_ :info "This is a notification"])]
|
||||||
|
(is (= :notification/hide (-> (:dispatch-later fx) first :dispatch first))))))
|
||||||
|
|
|
||||||
14
test/cljs/airsonic_ui/fixtures.cljs
Normal file
14
test/cljs/airsonic_ui/fixtures.cljs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
(ns airsonic-ui.fixtures)
|
||||||
|
|
||||||
|
(def responses {:error {:subsonic-response
|
||||||
|
{:error {:code 40
|
||||||
|
:message "Wrong username or password"}
|
||||||
|
:status "failed"
|
||||||
|
:version "1.15.0"}}
|
||||||
|
:ok {:subsonic-response
|
||||||
|
{:scanStatus {:count 10326
|
||||||
|
:scanning false}
|
||||||
|
:status "ok"
|
||||||
|
:version "1.15.0"}}
|
||||||
|
:auth-success {:subsonic-response {:status "ok"
|
||||||
|
:version "1.15.0"}}})
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
(ns airsonic-ui.utils.api-test
|
(ns airsonic-ui.utils.api-test
|
||||||
(:require [cljs.test :refer [deftest testing is]]
|
(:require [cljs.test :refer [deftest testing is]]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
|
[airsonic-ui.fixtures :refer [responses]]
|
||||||
[airsonic-ui.utils.api :as api]))
|
[airsonic-ui.utils.api :as api]))
|
||||||
|
|
||||||
(defn- url
|
(defn- url
|
||||||
|
|
@ -30,3 +31,19 @@
|
||||||
(is (true? (str/includes? (api/cover-url "http://server.tld" {} album -1) (str "id=" (:coverArt album))))))
|
(is (true? (str/includes? (api/cover-url "http://server.tld" {} album -1) (str "id=" (:coverArt album))))))
|
||||||
(testing "Should scale an image to a given size"
|
(testing "Should scale an image to a given size"
|
||||||
(is (true? (str/includes? (api/cover-url "http://server.tld" {} album 48) "size=48"))))))
|
(is (true? (str/includes? (api/cover-url "http://server.tld" {} album 48) "size=48"))))))
|
||||||
|
|
||||||
|
(deftest response-handling
|
||||||
|
(testing "Should unwrap responses"
|
||||||
|
(let [response (:ok responses)]
|
||||||
|
(is (= (get-in response [:subsonic-response :scanStatus])
|
||||||
|
(api/unwrap-response response)))))
|
||||||
|
(testing "Should detect errors"
|
||||||
|
(is (true? (api/is-error? (:error responses))))
|
||||||
|
(is (false? (api/is-error? (:ok responses)))))
|
||||||
|
(testing "Should throw an informative error when trying to unwrap an erroneous response"
|
||||||
|
(let [error-response (:error responses)]
|
||||||
|
(is (thrown? ExceptionInfo (api/unwrap-response error-response)))
|
||||||
|
(try
|
||||||
|
(api/unwrap-response error-response)
|
||||||
|
(catch ExceptionInfo e
|
||||||
|
(= (:error error-response) (ex-data e)))))))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue