This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-09
Channels
- # babashka (22)
- # beginners (58)
- # calva (14)
- # clj-kondo (3)
- # cljs-dev (4)
- # clojure (17)
- # clojure-dev (4)
- # clojure-italy (6)
- # clojure-uk (2)
- # clojurescript (32)
- # conjure (9)
- # cursive (2)
- # figwheel-main (48)
- # fulcro (77)
- # helix (2)
- # jobs-discuss (3)
- # joker (2)
- # pathom (3)
- # quil (3)
- # re-frame (24)
- # reitit (6)
- # shadow-cljs (11)
- # tools-deps (8)
- # xtdb (29)
I have the following effect in my reframe app that sends a get request:
(re-frame.core/reg-event-fx
:browse-products
(clojure.core/fn
[{:keys [db]} [___51233__auto__ location]]
(prn "browsing products")
{:http-xhrio
{:method :get,
:uri "/fetch-something",
:timeout 8000,
:params {:location location},
:on-success [:success],
:on-failure [:fail],
:response-format (ajax/json-response-format {:keywords? true})},
:db (assoc db :user-location (:description location))}))
And in the server side I print the response before sending it and seems to be okay:
{:status 200, :headers {"Content-Type" "application/edn", "Access-Control-Allow-Headers" "Content-Type", "Access-Control-Allow-Origin" "", "Access-Control-Request-Method" "GET, OPTIONS", "Access-Control-Allow-Credentials" true}, :body "[{:foo ...
But for some reason the on-failure event is being triggered. How do I identify the problem? How to fix this?printing the response on failure gives the following @mikethompson , where original-text is the right body
{:response nil, :last-method "GET", :original-text "[{:foo...
And the status?
@mikethompson status message is: Unexpected token : in JSON at position 2 Format should have been JSON keywordize
Seems like there's a problem with parsing, but why would that be? Do I need to change the response-format?
Hard to say. You'll have to debug. Maybe add:
:format (ajax/json-request-format)
to the effectYou send it EDN but ask to parse it as JSON. Just read the error message and see the payload that the client receives.
It's all in the documentation: https://github.com/JulianBirch/cljs-ajax/blob/master/docs/formats.md
using :detect gives ["keywords are not allowed as response formats in ajax calls: " :detect]
Apart from the table, there's other information. Literally the first sentence tells you what is expected of a format. Don't try blindly every visible option - just read the documentation. It's all there.
what's tripping me is that json-response-format did work for a different request. The only difference was that that was returning an edn map and not an edn vector, so I would expect this to work too
An empty EDN map is a valid JSON object. I cannot see any other way it could work though.
it works though for sure. In any case, I tried edn-response-format for this one. It stopped going for on-faliure, but in the on-success handler, this is what comes in as the parameter when printed: #ajax.interceptors.ResponseFormat{:read #object[ajax$edn$edn_read], :description "EDN", :content-type ["application/edn"]}