mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Fix exception log handler, *out* is not PrintWriter necessarily
This commit is contained in:
parent
c212a7a9fa
commit
a3aa5df111
3 changed files with 8 additions and 7 deletions
|
|
@ -80,7 +80,8 @@
|
|||
;; encoding response body
|
||||
muuntaja/format-response-middleware
|
||||
;; exception handling
|
||||
exception/exception-middleware
|
||||
(exception/create-exception-middleware
|
||||
{::exception/default (partial exception/wrap-log-to-console exception/default-handler)})
|
||||
;; decoding request body
|
||||
muuntaja/format-request-middleware
|
||||
;; coercing response bodys
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str])
|
||||
(:import (java.time Instant)
|
||||
(java.io PrintWriter)))
|
||||
(java.io PrintWriter Writer)))
|
||||
|
||||
(s/def ::handlers (s/map-of any? fn?))
|
||||
(s/def ::spec (s/keys :opt-un [::handlers]))
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
(wrap error-handler error request)
|
||||
(error-handler error request))))
|
||||
|
||||
(defn print! [^PrintWriter writer & more]
|
||||
(defn print! [^Writer writer & more]
|
||||
(.write writer (str (str/join " " more) "\n")))
|
||||
|
||||
;;
|
||||
|
|
@ -68,7 +68,7 @@
|
|||
|
||||
(defn wrap-log-to-console [handler ^Throwable e {:keys [uri request-method] :as req}]
|
||||
(print! *out* (Instant/now) request-method (pr-str uri) "=>" (.getMessage e))
|
||||
(.printStackTrace e ^PrintWriter *out*)
|
||||
(.printStackTrace e (PrintWriter. ^Writer *out*))
|
||||
(handler e req))
|
||||
|
||||
;;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str])
|
||||
(:import (java.time Instant)
|
||||
(java.io PrintWriter)))
|
||||
(java.io Writer PrintWriter)))
|
||||
|
||||
(s/def ::handlers (s/map-of any? fn?))
|
||||
(s/def ::spec (s/keys :opt-un [::handlers]))
|
||||
|
|
@ -55,7 +55,7 @@
|
|||
(catch Throwable e
|
||||
(on-exception handlers e request respond raise)))))))
|
||||
|
||||
(defn print! [^PrintWriter writer & more]
|
||||
(defn print! [^Writer writer & more]
|
||||
(.write writer (str (str/join " " more) "\n")))
|
||||
|
||||
;;
|
||||
|
|
@ -88,7 +88,7 @@
|
|||
|
||||
(defn wrap-log-to-console [handler ^Throwable e {:keys [uri request-method] :as req}]
|
||||
(print! *out* (Instant/now) request-method (pr-str uri) "=>" (.getMessage e))
|
||||
(.printStackTrace e ^PrintWriter *out*)
|
||||
(.printStackTrace e (PrintWriter. ^Writer *out*))
|
||||
(handler e req))
|
||||
|
||||
;;
|
||||
|
|
|
|||
Loading…
Reference in a new issue