Skip to content

Commit

Permalink
Look for public/404 and public/500 html files
Browse files Browse the repository at this point in the history
  • Loading branch information
swlkr committed Apr 24, 2019
1 parent 6e5e7a8 commit 1eb2228
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/coast/middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[clojure.stacktrace :as st]
[clojure.string :as string]
[clojure.data.json :as json]
[clojure.java.io :as io]
[ring.middleware.file]
[ring.middleware.keyword-params]
[ring.middleware.params]
Expand Down Expand Up @@ -162,13 +163,22 @@
[:body
[:h1 "500 Internal server error"]]])


(defn public-server-error [_]
(let [r (io/resource "public/500.html")]
(if (nil? r)
"500 Internal Server Error"
(slurp r))))


(defn wrap-site-errors [handler routes]
(if (not= "prod" (env/env :coast-env))
(wrap-exceptions handler)
(fn [request]
(let [error-fn (or (router/server-error-fn routes)
(utils/resolve-safely `site.home/server-error)
(utils/resolve-safely `home/server-error))]
(utils/resolve-safely `home/server-error)
public-server-error)]
(try
(handler request)
(catch Exception e
Expand All @@ -179,6 +189,13 @@
(res/server-error response :html))))))))


(defn public-not-found [_]
(let [r (io/resource "public/404.html")]
(if (nil? r)
"404 Not Found"
(slurp r))))


(defn wrap-not-found [handler routes]
(fn [request]
(let [[response error] (error/rescue
Expand All @@ -188,7 +205,8 @@
response
(let [not-found-fn (or (router/not-found-fn routes)
(utils/resolve-safely `site.home/not-found)
(utils/resolve-safely `home/not-found))]
(utils/resolve-safely `home/not-found)
public-not-found)]
(res/not-found
(not-found-fn request)
:html))))))
Expand Down

0 comments on commit 1eb2228

Please sign in to comment.