                              :handler #(binding [frontend.async/*uuid* uuid]
                                          (put! channel [message :success (assoc % :context context)]))
                              :error-handler #(binding [frontend.async/*uuid* uuid]
-                                               (put! channel [message :failed (normalize-error-response % url)]))
+                                               (put! channel [message :failed (normalize-error-response % {:url url :context context})]))
                              :finally #(binding [frontend.async/*uuid* uuid]
                                          (put! channel [message :finished context]))}))))
 

   :content-type "application/xml"
   :write identity})

(defn normalize-error-response [default-response url]
  (-> default-response
      (assoc :status-code (:status default-response))
      (assoc :resp (get-in default-response [:response :resp]))
      (assoc :status :failed)
      (assoc :url url)))

;; TODO only implementing JSON format and not implementing prefixes for now since we don't use either
(defn ajax [method url message channel & {:keys [params keywords? context headers]

                                             headers)
                             :handler #(put! channel (assoc % :status :success))
                             ;; TODO: clean this up
                             :error-handler #(put! channel (normalize-error-response % {:url url}))
                             :finally #(close! channel)}))
    channel))

