This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-10
Channels
- # announcements (4)
- # babashka (40)
- # beginners (39)
- # calva (16)
- # cljdoc (1)
- # cljs-dev (8)
- # clojure (72)
- # clojure-europe (10)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-spec (9)
- # clojure-uk (12)
- # clojurescript (16)
- # community-development (15)
- # conjure (5)
- # cursive (5)
- # datomic (26)
- # eastwood (1)
- # emacs (7)
- # events (1)
- # figwheel-main (15)
- # fulcro (27)
- # graphql (7)
- # gratitude (4)
- # introduce-yourself (1)
- # malli (4)
- # meander (4)
- # off-topic (2)
- # other-languages (13)
- # polylith (7)
- # reagent (5)
- # reitit (5)
- # shadow-cljs (27)
- # spacemacs (4)
- # sql (3)
- # tools-deps (6)
- # xtdb (13)
How do I set a user-agent header with clj-http
? Currently I have this expression with no header (paraphrasing):
(client/get my-url {:async? true} response-fn exception-fn)
there's an example in the readme: https://github.com/dakrone/clj-http#decompression
Oh, ha. I was digging through the source code and didn’t think to look for it there. Thanks!
Hello everyone I have a question. If an external api response is like this {:body {"errors":[{"message":"The provided authorization grant is invalid, expired, or revoked","field":null,"help":null}]}}. How can I get the errors value from here?
You can destructure it in this way:
(let [{{errors-value "errors"} :body} response]
(println "errors value is:" errors-value))
(get-in response [:body "errors"])
Sorry guys, but none of these worked. I guess the problem is that the response is not really a clojure map
That's correct, that seems like json, you'll have to parse it with cheshire or jsonista, or data.json and then run whichever these guys said.
yeah this doesn't make much sense.. it's a mix of json and clojure. if it was
{"body": {"errors":[{"message":"The provided authorization grant is invalid, expired, or revoked","field":null,"help":null}]}}
then it would make sense.I think the whole body is string
@U02S741T3DY To parse the json, you can try to use clojure/data.json
https://github.com/clojure/data.json
This isn’t trying to answer the original question, but @U02NELAR1S7 you may be interested to see that get-in
is flexible enough that you can get all the way down to the error message in an object like what was described:
(get-in response [:body "errors" 0 "message"])
@U051N6TTC Yes, I’ve looked into it and it’s really great. Really happy to have learned about it. Thank you!
Hello! I've recently gotten turned on to the concept of conditions and restarts through • this chapter in Practical Common Lisp: https://gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html • and this Clojure-specific talk on conditions in the Clojure ecosystem: https://youtu.be/zp0OEDcAro0 I'm interested to try out some condition libraries. So far I've found: • https://github.com/scgilardi/slingshot combined with https://github.com/hugoduncan/swell • https://github.com/bwo/conditions/ • https://github.com/IGJoshua/farolero • and https://github.com/clojureman/special Are there others I'm missing?
I don’t know of any others but #farolero is very nice and @U5NCUG8NR is quite responsive
special mentions most of the big players in the readme
except farolero
farolero is the closest you'll get to the experience in common lisp though @U01HMCQMBKP
Especially since as far as I've found no other library has the condition debugger
There is https://github.com/pangloss/pure-conditioning which takes a more clojure-specific approach to the problem while also strictly avoiding the (IMO awful) workaround of fully serializing all streams of data that are wrapped in condiition blocks to work around laziness in the language (!?!?!) like special pioneered.
bound-fn
solves most issues with laziness anyway.
for any of the versions based on dynamic variables
See @darrickw ‘s work (not sure if it is in the list yet?)
https://stuartsierra.com/2015/04/26/clojure-donts-concat is this article still relevant?
Yes, but I think it is more alarming then necessary. I do use concat freely, and never had any issues. The problem only arises with very large inputs, which in practice is rare that you'll have and use concat for.
If your use case suffers from this limitation than yes! But it's not necessarily that concatenating 50k+ maps into a vector would cause this. The issue is if you call concat over another sequence that itself is going to concat. As you capture one lazy-seq over another you build up a stack of functions, and when that stack grows too big you stackoverflow.
For example this is fine:
(def a
(doall
(concat
[]
(for [i (range 10000000)]
i))))
(count a)
Because in the last one you call concat on the previous result of concat, creating a stack of lazy concats waiting to realize themselves which when they do will stack overflow.
It goes to create something like: `(concat (concat (concat [1 2 3] [4 5 6]) [7 8 9]) [10 11 12])`
No problem. That's why the article also says technically this could happen for any lazy seq functions and not just concat. Anytime you'd build up this kind of recursive lazy sequence you could stackoverflow. For example this also stackoverflows:
(def a
(reduce
#(map + %1 %2)
(for [i (range 1 4000)]
(range 1 10))))