Skip to content

Commit 42016ae

Browse files
committed
section 2 video 5
1 parent 5a0fb18 commit 42016ae

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
66
:plugins [[lein-ring "0.8.7"]]
7-
:ring {:handler project1.core/route-handler
7+
:ring {:handler project1.core/wrapping-handler
88
:init project1.core/on-init
99
:port 4001
1010
:destroy project1.core/on-destroy}

src/project1/core.clj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
(println x "Hello, World!"))
2020

2121
(defn test1-handler [request]
22+
(throw (RuntimeException. "error!"))
2223
{:body "test1"})
2324

2425
(defn test2-handler [request]
@@ -30,3 +31,11 @@
3031
"/test2" (test2-handler request)
3132
"/test3" (handlers/handler3 request)
3233
nil))
34+
35+
(defn wrapping-handler [request]
36+
(try
37+
(if-let [resp (route-handler request)]
38+
resp
39+
{:status 404 :body (str "Not found: " (:uri request))})
40+
(catch Throwable e
41+
{:status 500 :body (apply str (interpose "\n" (.getStackTrace e)))})))

0 commit comments

Comments
 (0)