I am successfully getting a response from an endpoint using cljs-ajax (as shown below). However, I cannot seem to differentiate between different success status codes in my response handler.
(ns mynamespace
(:require [ajax.core :as ajax]))
(defn start-monitoring []
(let [handler (fn [[ok response]]
(if ok
(.log js/console response)
(.error js/console (str response))))]
(ajax/ajax-request {:uri "/myendpoint"
:method :get
:params {:since (.getTime (js/Date.))}
:handler handler
:format (ajax/json-request-format)
:response-format (ajax/json-response-format {:keywords? true})})))
"ok" in the handler appears to simply be a true/false success flag, and does not differentiate between 200 and 204 status codes, both of which are considered successes. The response body is whatever text is returned in the response, and doesn't appear to contain a status code, unless the request failed.
How can I determine the status code of the response?
Seems like the response is a map with keys like :status which contains 200 for my test.
The rest of the keys are:
(:status :failure :response :status-text :original-text)
Use :response-format (ajax/ring-response-format).
See also: https://github.com/JulianBirch/cljs-ajax/issues/57