Skip to content
Browse files
Try suppressing Broken pipe
  • Loading branch information
tonsky committed Jun 7, 2019
1 parent ec4a1eb commit fca324f142b1fd4076a2b834f2e0403103ceec0a
Showing with 18 additions and 1 deletion.
  1. +18 −1 src/grumpy/server.clj
@@ -6,6 +6,7 @@
[clojure.string :as str]
[io.pedestal.http :as http]
[ring.util.response :as response]
[clojure.stacktrace :as stacktrace]
[io.pedestal.interceptor :as interceptor]
[com.stuartsierra.component :as component]
[io.pedestal.http.ring-middlewares :as middlewares]
@@ -16,7 +17,8 @@
[grumpy.routes :as routes]
[grumpy.authors :as authors])
[java.util Date]))
[java.util Date]
[ IOException]))

(def page-size 5)
@@ -149,6 +151,20 @@
:body (grumpy/resource "robots.txt")})]))

(defn suppress-error [name class message-re]
{:name name
(fn [ctx ^Throwable e]
(let [cause (stacktrace/root-cause e)
message (.getMessage cause)]
(if (and (instance? class cause) (re-matches message-re message))
(println "Ignoring" (type cause) "-" message)
(assoc ctx :io.pedestal.interceptor.chain/error e))))}))

(defrecord Server [opts crux server]
(start [this]
@@ -161,6 +177,7 @@
::http/secure-headers {:content-security-policy-settings "object-src 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"}}
(update ::http/interceptors conj no-cache)
(update ::http/interceptors #(cons (suppress-error ::suppress-broken-pipe #"Broken pipe") %))
(assoc this :server server)))

0 comments on commit fca324f

Please sign in to comment.