diff --git a/src/asciinema/endpoint/asciicasts.clj b/src/asciinema/endpoint/asciicasts.clj index 687e888..a4517ae 100644 --- a/src/asciinema/endpoint/asciicasts.clj +++ b/src/asciinema/endpoint/asciicasts.clj @@ -7,7 +7,7 @@ [user-database :as udb]] [asciinema.model.asciicast :as asciicast] [asciinema.util.io :refer [with-tmp-dir]] - [asciinema.yada :refer [resource]] + [asciinema.yada :refer [resource not-found-model]] [clj-time.core :as t] [clojure.java [io :as io] @@ -103,4 +103,4 @@ (defn asciicasts-endpoint [{:keys [db file-store exp-set executor]}] ["" [["/a/" [[[:token ".json"] (asciicast-json-resource db file-store)] [[:token ".png"] (asciicast-png-resource db file-store exp-set executor)]]] - [true (yada/as-resource nil)]]]) + [true (yada/resource not-found-model)]]]) diff --git a/src/asciinema/yada.clj b/src/asciinema/yada.clj index e15788e..e2dafcc 100644 --- a/src/asciinema/yada.clj +++ b/src/asciinema/yada.clj @@ -2,14 +2,18 @@ (:require [clojure.java.io :as io] [yada.yada :as yada])) -(defn not-found-response [ctx] - (case (yada/content-type ctx) - "text/html" (io/input-stream (io/resource "asciinema/errors/404.html")) - "Not found")) +(def not-found-model + {:produces + #{"text/html" "text/plain"} + :response + (fn [ctx] + (assoc (:response ctx) + :status 404 + :body (case (yada/content-type ctx) + "text/html" (io/input-stream (io/resource "asciinema/errors/404.html")) + "Not found")))}) (defn resource [model] (-> model - (update-in [:responses 404] #(or % - {:produces #{"text/html" "text/plain"} - :response not-found-response})) + (update-in [:responses 404] #(or % not-found-model)) yada/resource))