 (ns clj-http-hystrix.core
   (:require [clj-http.client :as http]
-            [clojure.set :as set]
             [clojure.tools.logging :refer [warn error]]
             [robert.hooke :as hooke]
             [slingshot.slingshot :refer [get-thrown-object]]
             [slingshot.support :refer [wrap stack-trace]])
-  (:import [com.netflix.hystrix HystrixCommand HystrixThreadPoolProperties HystrixCommandProperties HystrixCommand$Setter HystrixCommandGroupKey$Factory HystrixCommandKey$Factory]
+  (:import [com.netflix.hystrix HystrixCommand
+                                HystrixThreadPoolProperties
+                                HystrixCommandProperties
+                                HystrixCommand$Setter
+                                HystrixCommandGroupKey$Factory
+                                HystrixCommandKey$Factory]
            [com.netflix.hystrix.exception HystrixBadRequestException]
            [org.slf4j MDC]))
 


(defn ^:private handle-exception
  [f req]
  (let [raw-response (try (f) (catch Exception e e))
        resp (if (instance? HystrixBadRequestException raw-response)
               (get-thrown-object (.getCause raw-response))
               raw-response)]

        (.andCommandPropertiesDefaults command-configurator)
        (.andThreadPoolPropertiesDefaults thread-pool-configurator))))

(defn ^:private log-error [command-name ^HystrixCommand context]
  (let [message (format "Failed to complete %s %s" command-name (.getExecutionEvents context))]
    (if-let [exception (.getFailedExecutionException context)]
      (warn exception message)
