dakrone / clj-http

An idiomatic clojure http client wrapping the apache client. Officially supported version.
http://clojars.org/clj-http
MIT License
1.78k stars 408 forks source link

Got connection refused exception #577

Closed vganshin closed 3 years ago

vganshin commented 3 years ago

Hello. I faced a little issue with clj-http "3.11.0".

I set up :throw-exceptions to false and try to send request to stopped service on http://localhost:8080 and I got Connection refused exception.

(ns user
  (:require [clj-http.client :as http]))

(http/request
 {:url "http://localhost:8080"
  :ignore-unknown-host? true
  :redirect-strategy :none
  :throw-exceptions false})

Few more samples:

;; Example from README
(http/get "http://example.invalid" {:ignore-unknown-host? true}) ;; => nil

(http/get "http://localhost:8080" {:ignore-unknown-host? true}) ;; Exception: Connection refused

(http/get "https://little.aidbox.app:1234" {:ignore-unknown-host? true}) ;; Exception: Operation timed out
rymndhng commented 3 years ago

Hey @vganshin, the behavior you're describing is expected of clj-http.

The option :throw-exceptions does not swallow all exceptions. It only changes the response handling behaviour when the status code is 4xx and 5xx.

vganshin commented 3 years ago

Oh, I got it. Thanks.