|
1 | 1 | (ns clj-http-hystrix.core |
2 | 2 | (:require [clj-http.client :as http] |
3 | | - [clojure.set :as set] |
4 | 3 | [clojure.tools.logging :refer [warn error]] |
5 | 4 | [robert.hooke :as hooke] |
6 | 5 | [slingshot.slingshot :refer [get-thrown-object]] |
7 | 6 | [slingshot.support :refer [wrap stack-trace]]) |
8 | | - (:import [com.netflix.hystrix HystrixCommand HystrixThreadPoolProperties HystrixCommandProperties HystrixCommand$Setter HystrixCommandGroupKey$Factory HystrixCommandKey$Factory] |
| 7 | + (:import [com.netflix.hystrix HystrixCommand |
| 8 | + HystrixThreadPoolProperties |
| 9 | + HystrixCommandProperties |
| 10 | + HystrixCommand$Setter |
| 11 | + HystrixCommandGroupKey$Factory |
| 12 | + HystrixCommandKey$Factory] |
9 | 13 | [com.netflix.hystrix.exception HystrixBadRequestException] |
10 | 14 | [org.slf4j MDC])) |
11 | 15 |
|
|
25 | 29 |
|
26 | 30 | (defn ^:private handle-exception |
27 | 31 | [f req] |
28 | | - (let [raw-response (try (f) (catch Exception e e)) |
| 32 | + (let [^Exception raw-response (try (f) (catch Exception e e)) |
29 | 33 | resp (if (instance? HystrixBadRequestException raw-response) |
30 | 34 | (get-thrown-object (.getCause raw-response)) |
31 | 35 | raw-response)] |
|
58 | 62 | (.andCommandPropertiesDefaults command-configurator) |
59 | 63 | (.andThreadPoolPropertiesDefaults thread-pool-configurator)))) |
60 | 64 |
|
61 | | -(defn ^:private log-error [command-name context] |
| 65 | +(defn ^:private log-error [command-name ^HystrixCommand context] |
62 | 66 | (let [message (format "Failed to complete %s %s" command-name (.getExecutionEvents context))] |
63 | 67 | (if-let [exception (.getFailedExecutionException context)] |
64 | 68 | (warn exception message) |
|
92 | 96 | :stack-trace (stack-trace)}))) |
93 | 97 | resp)) |
94 | 98 | wrap-exception-reponse (fn [resp] ((http/wrap-exceptions (constantly resp)) (assoc req :throw-exceptions true))) |
95 | | - configurator (configurator req) |
| 99 | + ^HystrixCommand$Setter configurator (configurator req) |
96 | 100 | logging-context (or (MDC/getCopyOfContextMap) {}) |
97 | 101 | command (proxy [HystrixCommand] [configurator] |
98 | 102 | (getFallback [] |
99 | 103 | (MDC/setContextMap logging-context) |
100 | 104 | (log-error (:hystrix/command-key req) this) |
101 | | - (let [exception (.getFailedExecutionException this) |
| 105 | + (let [exception (.getFailedExecutionException ^HystrixCommand this) |
102 | 106 | response (when exception (get-thrown-object exception))] |
103 | 107 | (fallback req response))) |
104 | 108 | (run [] |
|
0 commit comments