-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Description
Hi. Instead of using callbacks in handlers/middlewares I prefer to use promises.
The reason is that if I (or somebody else) forget to handle some error - I can still set some handling and return 500 instead of waiting for timeout.
Currently I am using this middleware to take care of unexpected errors in my handlers:
(ns app.routes.middleware.rejection
(:require
[taoensso.timbre :as timbre]))
(defn wrap-rejection
"Middleware returns `500` if handler returned rejected promise and logs the error."
[handler]
(fn [req res raise]
(let [result (handler req res raise)]
(when (instance? js/Promise result)
(.catch result
(fn [e]
(timbre/error e "Rejection middleware caught error")
(res {:status 500})))))))
Would you accept possible prs that would convert callbacks into promises like
| (handle body)))))) |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels