Skip to content

Commit

Permalink
Merge branch 'pr/343'
Browse files Browse the repository at this point in the history
  • Loading branch information
dakrone committed Dec 13, 2016
2 parents 731c19f + 2892c2a commit 04dd083
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/clj_http/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@
resp
(if (false? (opt req :throw-exceptions))
resp
(if (opt req :throw-entire-message)
(throw+ resp "clj-http: status %d %s" (:status %) resp)
(throw+ resp "clj-http: status %s" (:status %))))))
(let [data (assoc resp :type ::unexceptional-status)]
(if (opt req :throw-entire-message)
(throw+ data "clj-http: status %d %s" (:status %) resp)
(throw+ data "clj-http: status %s" (:status %)))))))

(defn wrap-exceptions
"Middleware that throws a slingshot exception if the response is not a
Expand Down
13 changes: 12 additions & 1 deletion test/clj_http/test/client_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
[clojure.test :refer :all]
[cognitect.transit :as transit]
[ring.util.codec :refer [form-decode-str]]
[ring.middleware.nested-params :refer [parse-nested-keys]])
[ring.middleware.nested-params :refer [parse-nested-keys]]
[slingshot.slingshot :refer [try+]])
(:import (java.net UnknownHostException)
(java.io ByteArrayInputStream)
(org.apache.http HttpEntity)))
Expand Down Expand Up @@ -496,6 +497,16 @@
(is (thrown-with-msg? Exception #":body"
(e-client {:throw-entire-message? true})))))

(deftest throw-type-field
(let [client (fn [req] {:status 500})
e-client (client/wrap-exceptions client)]
(try+
(e-client {})
(catch [:type :clj-http.client/unexceptional-status] _
(is true))
(catch Object _
(is false ":type selector was not caught.")))))

(deftest throw-on-exceptional-async
(let [client (fn [req respond raise]
(try
Expand Down

0 comments on commit 04dd083

Please sign in to comment.