Skip to content
Browse files

recognize :throw-exceptions options to surpress throwing on exception…

…al responses
  • Loading branch information...
1 parent f2e93d2 commit 85b5277ffde6d011135f355790285e3add362b11 @mmcgrana committed
Showing with 8 additions and 1 deletion.
  1. +2 −1 src/clj_http/client.clj
  2. +6 −0 test/clj_http/client_test.clj
View
3 src/clj_http/client.clj
@@ -28,7 +28,8 @@
(defn wrap-exceptions [client]
(fn [req]
(let [{:keys [status] :as resp} (client req)]
- (if (unexceptional-status? status)
+ (if (or (not (clojure.core/get req :throw-exceptions true))
+ (unexceptional-status? status))
resp
(throw (CljHttpException.
(str "Response: " status)
View
6 test/clj_http/client_test.clj
@@ -79,6 +79,12 @@
resp (e-client {})]
(is (= 200 (:status resp)))))
+(deftest pass-on-exceptional-when-surpressed
+ (let [client (fn [req] {:status 500})
+ e-client (client/wrap-exceptions client)
+ resp (e-client {:throw-exceptions false})]
+ (is (= 500 (:status resp)))))
+
(deftest apply-on-compressed
(let [client (fn [req] {:body (util/gzip (util/utf8-bytes "foofoofoo"))

0 comments on commit 85b5277

Please sign in to comment.
Something went wrong with that request. Please try again.