This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-27
Channels
- # announcements (2)
- # babashka (24)
- # beginners (116)
- # cider (7)
- # cljsrn (6)
- # clojure (38)
- # clojure-bay-area (4)
- # clojure-europe (3)
- # clojure-losangeles (1)
- # clojure-norway (10)
- # clojurescript (171)
- # datomic (16)
- # honeysql (3)
- # improve-getting-started (1)
- # introduce-yourself (2)
- # java (12)
- # malli (5)
- # membrane (2)
- # pedestal (3)
- # shadow-cljs (79)
- # spacemacs (6)
- # xtdb (10)
I'm using babashka.curl/request
to do a patch
request with a map like this:
{:headers
{"Accept" "application/vnd.pulumi+8",
"Content-Type" "application/json",
"Authorization" "token XXX"},
:url "",
:body
"{\"addStackPermission\":{\"projectName\":\"my-project\",\"stackName\":\"my-stack\",\"permission\":101}}",
:method :patch}
If myteam
(in the URL) is invalid, an exception is thrown:
; java.util.concurrent.ExecutionException: babashka.curl: status 404 user /Users/my-user/Code/my-org/flashcli/src/pulumi.clj:1:1
https://github.com/babashka/babashka.curl#exceptions, I see (:status (ex-data *e)
can be used to get the exception data or use {:throw false}
to prevent throwing.
But those do not seem to work with babashka.curl/request
(only with babashka.curl/get
, etc.)
Can I somehow get the exception data or avoid throwing with babashka.curl/request
as well? I prefer using babashka.curl/request
because it lets me build up the HTTP request as pure data (maps) in a very ergonomic way prior to actually making the request.Ah! I didn't actually check, because the examples in the docs show it like this:
(curl/get "")
;;=> Execution error (ExceptionInfo) at babashka.curl/request (curl.clj:228).
status 404
(:status (ex-data *e))
;;=> 404
(:status (curl/get "" {:throw false}))
;;=> 404
I presumed it would work with get
based on that. But I may have misunderstood the docs.the url being an invalid endpoint is a special case which isn't handled as an error while actually processing the request, I think
I suppose I'll stick to http-kit
implementation, then! I got that working well, but I wanted to simplify by avoiding async and callbacks.
borkdude@m1 ~ $ curl foobar
curl: (6) Could not resolve host: foobar
borkdude@m1 ~ $ echo $?
6
I think it's better to use babashka.http-client than bb.curl btw, bb.curl is kinda deprecated in favor of that
but bb.http-client may have the same problem, which could be fixed potentially if you can make an issue
Oooh! I was adding http-kit
as a dependency myself. I wasn't aware it actually comes bundled with Babashka. Nice!
If I can use the HTTP stuff that comes with Babashka, I prefer that over importing another lib.
The same exception occurs with invalid parameters in the URI when using babashka.http-client
. I can create an issue if it's helpful. The exception does not happen with org.httpkit.client
(using the same request map), so perhaps that could be a good reference.
I already knew about this issue and it's disputable what to do here because of how it's handled in Java itself
Interestingly, the status code (404) is included in the exception printed to the console.
Also, I want to take a moment to appreciate https://gist.github.com/leifericf/242fb222966c8cfc8beb04539aaf8fab/revisions using Clojure and Babashka. Man, what an excellent language and library.