display server errors to the user in on-error events
This commit is contained in:
parent
ef8240ecc0
commit
2c7bfc21e1
|
@ -17,13 +17,15 @@
|
||||||
[card-id quality foil? list-id]
|
[card-id quality foil? list-id]
|
||||||
(ajax/POST (->url "/collection/add")
|
(ajax/POST (->url "/collection/add")
|
||||||
:params {:card-id card-id :quality quality :foil foil? :list-id list-id}
|
:params {:card-id card-id :quality quality :foil foil? :list-id list-id}
|
||||||
:on-error #(set-error! "Server error while adding card to inventory.")))
|
:on-error (fn [{:keys [response]}]
|
||||||
|
(set-error! (str "Server error while updating card inventory: " (get response "message"))))))
|
||||||
|
|
||||||
(defn on-remove-card
|
(defn on-remove-card
|
||||||
[card-id quality foil? list-id]
|
[card-id quality foil? list-id]
|
||||||
(ajax/POST (->url "/collection/remove")
|
(ajax/POST (->url "/collection/remove")
|
||||||
:params {:card-id card-id :quality quality :foil foil? :list-id list-id}
|
:params {:card-id card-id :quality quality :foil foil? :list-id list-id}
|
||||||
:on-error #(set-error! "Server error while adding card to inventory.")))
|
:on-error (fn [{:keys [response]}]
|
||||||
|
(set-error! (str "Server error while updating card inventory: " (get response "message"))))))
|
||||||
|
|
||||||
(defn can-modify-inventory?
|
(defn can-modify-inventory?
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
(reset! error "List name must be provided.")
|
(reset! error "List name must be provided.")
|
||||||
(ajax/POST (->url "/lists/add")
|
(ajax/POST (->url "/lists/add")
|
||||||
:params {:name name :public? public? :requires-qualities? requires-qualities?}
|
:params {:name name :public? public? :requires-qualities? requires-qualities?}
|
||||||
:on-error #(reset! error "Could not create list. Make sure list name is unique.")
|
:on-error (fn [{:keys [response]}]
|
||||||
|
(reset! error (str "Server error: " (get response "message"))))
|
||||||
:on-success (fn [response]
|
:on-success (fn [response]
|
||||||
(let [new-list-id (:id (clojure.walk/keywordize-keys response))]
|
(let [new-list-id (:id (clojure.walk/keywordize-keys response))]
|
||||||
(redirect! (str "#/list/" new-list-id))))))))
|
(redirect! (str "#/list/" new-list-id))))))))
|
||||||
|
@ -93,7 +94,8 @@
|
||||||
(reset! error "List name must be provided.")
|
(reset! error "List name must be provided.")
|
||||||
(ajax/POST (->url "/lists/update-name")
|
(ajax/POST (->url "/lists/update-name")
|
||||||
:params {:list-id list-id :name name}
|
:params {:list-id list-id :name name}
|
||||||
:on-error #(reset! error "Could not update list name. Make sure the name is unique.")
|
:on-error (fn [{:keys [response]}]
|
||||||
|
(reset! error (str "Server error: " (get response "message"))))
|
||||||
:on-success #(on-close)))))
|
:on-success #(on-close)))))
|
||||||
on-key-up #(if (= 13 (.-keyCode %))
|
on-key-up #(if (= 13 (.-keyCode %))
|
||||||
(on-submit))]
|
(on-submit))]
|
||||||
|
@ -134,7 +136,8 @@
|
||||||
(ajax/POST (->url "/collection/copy-list")
|
(ajax/POST (->url "/collection/copy-list")
|
||||||
:params {:source-list-id source-list-id
|
:params {:source-list-id source-list-id
|
||||||
:destination-list-id destination-list-id}
|
:destination-list-id destination-list-id}
|
||||||
:on-error #(reset! error "Error copying the list.")
|
:on-error (fn [{:keys [response]}]
|
||||||
|
(reset! error (str "Server error: " (get response "message"))))
|
||||||
:on-success #(on-close)))))
|
:on-success #(on-close)))))
|
||||||
on-key-up #(if (= 13 (.-keyCode %))
|
on-key-up #(if (= 13 (.-keyCode %))
|
||||||
(on-submit))]
|
(on-submit))]
|
||||||
|
@ -176,7 +179,8 @@
|
||||||
[bs/Button
|
[bs/Button
|
||||||
{:bsStyle "primary"
|
{:bsStyle "primary"
|
||||||
:on-click on-submit
|
:on-click on-submit
|
||||||
:disabled (string/blank? (:destination-list-id @values))} "OK"]
|
:disabled (string/blank? (:destination-list-id @values))}
|
||||||
|
"OK"]
|
||||||
[bs/Button {:on-click on-close} "Cancel"]]]))))
|
[bs/Button {:on-click on-close} "Cancel"]]]))))
|
||||||
|
|
||||||
|
|
||||||
|
@ -222,19 +226,22 @@
|
||||||
[list-id notes]
|
[list-id notes]
|
||||||
(ajax/POST (->url "/lists/update-note")
|
(ajax/POST (->url "/lists/update-note")
|
||||||
:params {:list-id list-id :note notes}
|
:params {:list-id list-id :note notes}
|
||||||
:on-error #(set-error! "Server error while updating list notes.")))
|
:on-error (fn [{:keys [response]}]
|
||||||
|
(set-error! (str "Server error while updating list notes: " (get response "message"))))))
|
||||||
|
|
||||||
(defn change-list-visibility!
|
(defn change-list-visibility!
|
||||||
[list-id public?]
|
[list-id public?]
|
||||||
(ajax/POST (->url "/lists/update-visibility")
|
(ajax/POST (->url "/lists/update-visibility")
|
||||||
:params {:list-id list-id :public? public?}
|
:params {:list-id list-id :public? public?}
|
||||||
:on-error #(set-error! "Server error while updating list public/private visibility.")))
|
:on-error (fn [{:keys [response]}]
|
||||||
|
(set-error! (str "Server error while updating list public/private visibility: " (get response "message"))))))
|
||||||
|
|
||||||
(defn delete-list!
|
(defn delete-list!
|
||||||
[list-id]
|
[list-id]
|
||||||
(ajax/POST (->url "/lists/remove")
|
(ajax/POST (->url "/lists/remove")
|
||||||
:params {:list-id list-id}
|
:params {:list-id list-id}
|
||||||
:on-error #(set-error! "Server error while deleting the list.")
|
:on-error (fn [{:keys [response]}]
|
||||||
|
(set-error! (str "Server error while deleting the list: " (get response "message"))))
|
||||||
:on-success #(redirect! "#/lists")))
|
:on-success #(redirect! "#/lists")))
|
||||||
|
|
||||||
(defonce list-cards-search-filters
|
(defonce list-cards-search-filters
|
||||||
|
|
Loading…
Reference in a new issue