diff --git a/src/asciinema/yada.clj b/src/asciinema/yada.clj index b310196..573a0ee 100644 --- a/src/asciinema/yada.clj +++ b/src/asciinema/yada.clj @@ -1,6 +1,7 @@ (ns asciinema.yada (:require [clojure.java.io :as io] [taoensso.timbre :as log] + [yada.status :as status] [yada.yada :as yada])) (def not-found-model @@ -14,13 +15,23 @@ "text/html" (io/input-stream (io/resource "asciinema/errors/404.html")) "Not found")))}) +(defn error-response [ctx] + (let [status (-> ctx :response :status) + status-name (get-in status/status [status :name])] + (case (yada/content-type ctx) + "text/html" (str "

" status-name "

") + status-name))) + (defn logger [ctx] (when-let [error (:error ctx)] (when (not= (-> ctx :response :status) 404) (log/error error)))) (defn resource [model] - (-> model - (assoc :logger logger) - (update-in [:responses 404] #(or % not-found-model)) - yada/resource)) + (let [error-statuses (set (concat (range 400 404) (range 405 600) ))] + (-> model + (assoc :logger logger) + (update-in [:responses 404] #(or % not-found-model)) + (update-in [:responses error-statuses] #(or % {:produces #{"text/html" "text/plain"} + :response error-response})) + yada/resource)))