Comments (8)
+1 from me. I need this too.
The problem is that the exception-throwing middleware discards everything except the status code, which it stringifies and sets as the exception's message. I would like to see the whole response object attached to the exception. But of course, this means having an exception class that can carry a non-string payload.
I see at least three ways to do this:
- Revive the "exceptions" branch, which seems to have been started and then abandoned by Mark about a year ago.
- Add a dependency on slingshot, which seems to be the closest thing to a community-standard exception library.
- Wait for Clojure 1.4, which is (I think) going to add some sort of data-carrying exception type.
I would vote for 2 as the quickest, simplest solution.
from clj-http.
I will probably do this with a dependency on slingshot, the exceptions branch is basically a stripped down slingshot. I'll work on this.
from clj-http.
How feasible would it be to add a debug mode where you could see all the
headers? Like -vvv
in curl.
For the record, the problem was I was sending a body of "From=kevin&Body=hello", like this
client/post url {:body body}
When I changed it to sending a map using form-params
it worked fine.
On Monday, October 17, 2011, Chris Perkins wrote:
+1 from me. I need this too.
The problem is that the exception-throwing middleware discards everything
except the status code, which it stringifies and sets as the exception's
message. I would like to see the whole response object attached to the
exception. But of course, this means having an exception class that can
carry a non-string payload.I see at least three ways to do this:
- Revive the "exceptions" branch, which seems to have been started and
then abandoned by Mark about a year ago.- Add a dependency on slingshot, which seems to be the closest thing to a
community-standard exception library.- Wait for Clojure 1.4, which is (I think) going to add some sort of
data-carrying exception type.I would vote for 2 as the quickest, simplest solution.
Reply to this email directly or view it on GitHub:
#12 (comment)
Kevin Burke | Twilio
phone: 925.271.7005 | kev.inburke.com
from clj-http.
So now (when the slingshot-exception branch gets merged in) clj-http will throw a Stone with the entire response, which can either be caught with a regular (try (get ...) (catch Exception e ...)) or caught with Slingshot's try+ (excuse the bad formatting):
user=> (get "http://github.com/faoeu")
Stone Object thrown by throw+: {:status 404, :headers {"server" "nginx/1.0.4", "x-runtime" "12ms", "content-encoding" "gzip", "strict-transport-security" "max-age=2592000", "x-frame-options" "deny", "content-type" "text/html; charset=utf-8", "date" "Mon, 17 Oct 2011 23:15 :36 GMT", "set-cookie" "_gh_sess=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--ed7eadd474fd37850b68bd3c08a5c55ad0c3c833; path=/; expires=Fri, 01 Jan 2021 00:00:00 GMT; secure; HttpOnly", "cache-control" "no-cache", "status" "404 Not Found", "transfer-encoding" "chunked", "connection" "close"}, :body "....very large body here...."} clj-http.client/wrap-exceptions/fn--227 (client.clj:37)
from clj-http.
In the same branch, I'm also considering adding a (secret!) :debug flag that prints the request to standard out, so people can see exactly what flags are being set on the HttpRequest object:
user=> (get "http://aoeu.com" {:debug true})
Request:
{:query-string nil,
:user-info nil,
:uri "",
:server-port 80,
:server-name "aoeu.com",
:scheme "http",
:headers {"Accept-Encoding" "gzip, deflate"},
:request-method :get,
:debug true}
HttpRequest:
{:requestLine #<BasicRequestLine GET http://aoeu.com:80 HTTP/1.1>,
:protocolVersion #<HttpVersion HTTP/1.1>,
:params
#<BasicHttpParams org.apache.http.params.BasicHttpParams@1fb88122>,
:method "GET",
:class org.apache.http.client.methods.HttpGet,
:allHeaders
[#<BasicHeader Connection: close>,
#<BasicHeader Accept-Encoding: gzip, deflate>],
:aborted false,
:URI #<URI http://aoeu.com:80>}
from clj-http.
I've merged this to master. Can you guys take a look and let me know what you think? If this fits your needs I'll cut a point release so it's available on Clojars.
from clj-http.
Works great for me. Thanks.
The :debug flag is nice. One other possibility is to use it to print the response as well if an exception is thrown:
(defn wrap-exceptions [client]
(fn [req]
(let [{:keys [status] :as resp} (client req)]
(if (or (not (clojure.core/get req :throw-exceptions true))
(unexceptional-status? status))
resp
(do
(when (:debug req)
(println "Response:")
(clojure.pprint/pprint resp))
(throw+ resp))))))
But I can take or leave that - I can catch and print the exception anyway now.
from clj-http.
Awesome, I released a 0.2.2 version, lemme know if you have any more issues with it.
from clj-http.
Related Issues (20)
- Switch to built in http client (introduced in java 11) HOT 3
- Severe security vulnerability in used version of log4j2 HOT 2
- Skip query param encoding? HOT 3
- Parse-transit will ignore body is input-stream doesn't have data available right away HOT 2
- Async HTTP Request Connection Timeout Not Work Correctly HOT 3
- The word 'officially' is spelt wrong in the GitHub description HOT 1
- HEAD requests shouldn't discard body (in the request).
- Handling of private proxies HOT 2
- Whenever I get a 405 response from a server, a null pointer exception is thrown because the connection wasn't found HOT 1
- Nested query params
- cookie-policy none
- URL encoding of whitespace should be "%20" instead of "+" in query parameters HOT 1
- Calling `.close` on response http stream will fully read stream contents rather than terminating. HOT 2
- `:query-params` are re-ordered
- :threads is mis-named and mis-documented
- multipart posts: sending name requires a mime-type
- Async requests not really async
- AOT issues with clj_http.headers.HeaderMap HOT 4
- url path parameters HOT 2
- The :redirect-strategy doesn't seem to work for PUT and PATCH HTTP methods
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clj-http.