 
 (defn- update-note [{:keys [note-id] :as note} rsp-ch]
   (go
-    (let [srv-ch (http/put (str "/note/" note-id) {:query-params (get-update-note-params note)})
-          {:keys [status body]} (<! srv-ch)]
+    (let [{:keys [status body]} (<! (http/put (str "/note/" note-id) {:query-params (get-update-note-params note)}))]
       (case status
         200 (put! rsp-ch {:ok? true})
-        401 (put! rsp-ch {:ok? false})
-        (println "hmz") ; TODO: define return value {:ok? true/false :}
+        (put! rsp-ch {:ok? false :error body})
   ))))
 
 (defn- get-note [note-id rsp-ch]

            [cljs-http.client :as http]
  ))

;;; helpers

(defn- get-sign-url [type]
  (case type
    :sign-in "/user/session"
    :sign-up "/user"))


(defn- reply [ch ]

  )

(defn- srv-op []

  )

; (defn mutate-and-put! [op ch state k v]
;   (op state k v)
;   (put! ch {k v})
;   )

;;; server operations

; TODO: fix signatures

(defn- sign [type user pass rsp-ch]
  (go

    (let [{:keys [status body] :as srv-rsp} (<! (http/get (str "/note/" note-id)))]
      (case status
        200 (put! rsp-ch {:ok? true :note body})
        (put! rsp-ch {:ok? false :error body})
  ))))

;;; server control

(defn init [ch]
  (go (while true
    (let [{:keys [tag rsp-ch] :as data} (<! ch)]
      (case tag
        ; TODO: xxx
        :sign-up (println "sign-up" data)
        :sign-in (println "sign-in" data)
        :sign-out (println "sign-out" data)
        :create-note (create-note (:user-id data) (:text data) (:visibility data) rsp-ch)
        :delete-note (delete-note (:note-id data) rsp-ch)
        :update-note (update-note (:note data) rsp-ch)
        :get-note (get-note (:note-id data) rsp-ch)
        :get-private-notes (get-private-notes (:user-id data) rsp-ch)
        :get-public-notes (get-public-notes rsp-ch)
        (do
          (println "oops" data)
          (put! rsp-ch data))
