Skip to content

Commit ca310cc

Browse files
alexander-yakushevztellman
authored andcommitted
Minor fixes in client_middleware.clj (#429)
* Fix outdated docstring for wrap-exceptions * Remove unused functions from client-middleware * Remove redundant executor rescheduling if body shouldn't be coerced
1 parent fce2fd8 commit ca310cc

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

src/aleph/http/client_middleware.clj

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
(ns aleph.http.client-middleware
22
"This middleware is adapted from clj-http, whose license is amenable to this sort of
33
copy/pastery"
4-
(:refer-clojure :exclude [update])
54
(:require
65
[potemkin :as p]
76
[clojure.string :as str]
@@ -110,26 +109,9 @@
110109

111110
;;;
112111

113-
(defn update [m k f & args]
114-
(assoc m k (apply f (m k) args)))
115-
116112
(defn when-pos [v]
117113
(when (and v (pos? v)) v))
118114

119-
(defn dissoc-in
120-
"Dissociates an entry from a nested associative structure returning a new
121-
nested structure. keys is a sequence of keys. Any empty maps that result
122-
will not be present in the new structure."
123-
[m [k & ks :as keys]]
124-
(if ks
125-
(if-let [nextmap (clojure.core/get m k)]
126-
(let [newmap (dissoc-in nextmap ks)]
127-
(if (seq newmap)
128-
(assoc m k newmap)
129-
(dissoc m k)))
130-
m)
131-
(dissoc m k)))
132-
133115
(defn url-encode
134116
([^String s]
135117
(url-encode s "UTF-8"))
@@ -252,9 +234,9 @@
252234
type))
253235

254236
(defn wrap-exceptions
255-
"Middleware that throws a slingshot exception if the response is not a
256-
regular response. If :throw-entire-message? is set to true, the entire
257-
response is used as the message, instead of just the status number."
237+
"Middleware that throws response as an ExceptionInfo if the response has
238+
unsuccessful status code. :throw-exceptions set to false in the request
239+
disables this middleware."
258240
[client]
259241
(fn [req]
260242
(d/let-flow' [{:keys [status body] :as rsp} (client req)]
@@ -967,7 +949,7 @@
967949
;; coerce the response body
968950
(fn [{:keys [body] :as rsp}]
969951
(let [rsp' (handle-response-debug req' rsp)]
970-
(if (nil? body)
971-
rsp'
952+
(if (and (some? body) (some? (:as req')))
972953
(d/future-with (or executor (ex/wait-pool))
973-
(coerce-response-body req' rsp'))))))))))))
954+
(coerce-response-body req' rsp'))
955+
rsp'))))))))))

0 commit comments

Comments
 (0)