Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
How to get status code of successful response in handler in cljs-ajax?

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?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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)

over 4 years ago · Santiago Trujillo Relatório

0

Use :response-format (ajax/ring-response-format). See also: https://github.com/JulianBirch/cljs-ajax/issues/57

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda