From ef12bb974c513dfa29f4548c27e2e86771c9595f Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 30 Mar 2014 04:58:03 -0400 Subject: [PATCH] adjustments to malformed / not-found request handlers --- src/toascii/routes/api/text.clj | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/toascii/routes/api/text.clj b/src/toascii/routes/api/text.clj index 798b676..346d6b9 100644 --- a/src/toascii/routes/api/text.clj +++ b/src/toascii/routes/api/text.clj @@ -16,12 +16,14 @@ {:representation {:media-type type}})) :malformed? (fn [_] - (str/blank? s)) + (cond + (str/blank? s) {:error "Missing text to render"})) :exists? (fn [ctx] (let [font-name (or font "standard")] (if-let [flf (get-font font-name)] - {:flf flf}))) + {:flf flf} + [false {:error "Font not found."}]))) :handle-ok (fn [ctx] (let [rendered (figlet/render-to-string (:flf ctx) s)] @@ -29,11 +31,11 @@ (str "
" rendered "
") rendered))) :handle-malformed - (fn [_] - "Missing text to render.") + (fn [ctx] + (:error ctx)) :handle-not-found - (fn [_] - "Font not found.")) + (fn [ctx] + (:error ctx))) (register-routes api-text-routes (ANY "/api/text" {params :params} (render-text params)))