Skip to content

Commit 37485c8

Browse files
author
Ulf Gitschthaler
committed
Add bad-request-pred function again
1 parent 9f62aff commit 37485c8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/clj_http_hystrix/core.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
:hystrix/timeout-ms 1000
4444
:hystrix/breaker-request-volume 20
4545
:hystrix/breaker-error-percent 50
46-
:hystrix/breaker-sleep-window-ms 5000})
46+
:hystrix/breaker-sleep-window-ms 5000
47+
:hystrix/bad-request-pred client-error?})
4748

4849
(def ^:private hystrix-keys
4950
(keys hystrix-base-configuration))
@@ -108,10 +109,11 @@
108109
(fn [f req]
109110
(if (not-empty (select-keys req hystrix-keys))
110111
(let [req (merge defaults req)
112+
bad-request-pred (:hystrix/bad-request-pred req)
111113
fallback (:hystrix/fallback-fn req)
112114
wrap-exception-response (fn [resp]
113115
((http/wrap-exceptions (constantly resp))
114-
(assoc req :throw-exceptions (not (client-error? req resp)))))
116+
(assoc req :throw-exceptions (not (bad-request-pred req resp)))))
115117
configurator (configurator req)
116118
logging-context (or (MDC/getCopyOfContextMap) {})
117119
command (proxy [HystrixCommand] [configurator]

test/clj_http_hystrix/core_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
:throw-exceptions false})]
114114
(:status response) => 503)))
115115

116-
(fact "errors will not cause circuit to break if client-error? is true, with :throw-exceptions false"
116+
(fact "errors will not cause circuit to break if bad-request-pred is true, with :throw-exceptions false"
117117
(rest-driven
118118
[{:method :GET
119119
:url "/"}
@@ -130,7 +130,7 @@
130130
(http/get url {:throw-exceptions false
131131
:hystrix/command-key command-key}) => (contains {:status 200}))))
132132

133-
(fact "errors will not cause circuit to break if client-error? is true, with :throw-exceptions true"
133+
(fact "errors will not cause circuit to break if bad-request-pred is true, with :throw-exceptions true"
134134
(rest-driven
135135
[{:method :GET
136136
:url "/"}

0 commit comments

Comments
 (0)