Skip to content
Snippets Groups Projects
Commit b8120886 authored by Cam Saül's avatar Cam Saül Committed by Arthur Ulfeldt
Browse files

handle exceptions

parent 5d1cf651
Branches
Tags
No related merge requests found
......@@ -53,6 +53,9 @@
(Thread/sleep 30000)
{:success true})
(defn- some-naughty-handler-that-barfs [_]
(throw (Exception. "BARF!")))
(def ^:private ^:const streaming-response-keep-alive-interval-ms
"Interval between sending whitespace bytes to keep Heroku from terminating
requests like queries that take a long time to complete."
......@@ -60,9 +63,14 @@
(defn- streaming-response [handler]
(fn [request]
;; TODO - handle exceptions & have some sort of maximum timeout for these requests
;; TODO - need maximum timeout for requests
;; TODO - error response should have status code != 200 (how ?)
;; TODO - handle exceptions in JSON encoding as well
(-> (fn [^java.io.PipedOutputStream ostream]
(let [response (future (handler request))
(let [response (future (try (handler request)
(catch Throwable e
{:error (.getMessage e)
:stacktrace (u/filtered-stacktrace e)})))
write-response (future (json/generate-stream @response (io/writer ostream))
(println "Done! closing ostream...")
(.close ostream))]
......@@ -103,5 +111,7 @@
(context "/embed" [] embed-routes)
(context "/stream-test" []
(streaming-response some-very-long-handler))
(context "/stream-test-2" []
(streaming-response some-naughty-handler-that-barfs))
;; Anything else (e.g. /user/edit_current) should serve up index.html; React app will handle the rest
(GET "*" [] index))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment