这是您可以轻松重现 timeout 的方法:
(http/get "http://google.com" {:timeout 1}
(fn [{:keys [status headers body error]}] ;; asynchronous response handling
(if error
(do
(if (instance? org.httpkit.client.TimeoutException error)
(println "There was timeout")
(println "There wasn't timeout"))
(println "Failed, exception is " error))
(println "Async HTTP GET: " status))))
它将打印错误,这是 org.httpkit.client.TimeoutException 的一个实例
因此,您必须更改回调以接受地图。如果出现错误,此映射中的 :error 字段不为零,如果超时,它将包含 TimeoutException。顺便说一句,这只是客户端文档中稍作修改的示例- 我认为它在那里得到了很好的解释。
因此,尝试将您的回调更改为:
(defn post-callback
[{:keys [status headers body error]}]
;; and check the error same way as I do above
)