adjustments to malformed / not-found request handlers
This commit is contained in:
parent
2e9cca8e4c
commit
ef12bb974c
|
@ -16,12 +16,14 @@
|
||||||
{:representation {:media-type type}}))
|
{:representation {:media-type type}}))
|
||||||
:malformed?
|
:malformed?
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(str/blank? s))
|
(cond
|
||||||
|
(str/blank? s) {:error "Missing text to render"}))
|
||||||
:exists?
|
:exists?
|
||||||
(fn [ctx]
|
(fn [ctx]
|
||||||
(let [font-name (or font "standard")]
|
(let [font-name (or font "standard")]
|
||||||
(if-let [flf (get-font font-name)]
|
(if-let [flf (get-font font-name)]
|
||||||
{:flf flf})))
|
{:flf flf}
|
||||||
|
[false {:error "Font not found."}])))
|
||||||
:handle-ok
|
:handle-ok
|
||||||
(fn [ctx]
|
(fn [ctx]
|
||||||
(let [rendered (figlet/render-to-string (:flf ctx) s)]
|
(let [rendered (figlet/render-to-string (:flf ctx) s)]
|
||||||
|
@ -29,11 +31,11 @@
|
||||||
(str "<pre>" rendered "</pre>")
|
(str "<pre>" rendered "</pre>")
|
||||||
rendered)))
|
rendered)))
|
||||||
:handle-malformed
|
:handle-malformed
|
||||||
(fn [_]
|
(fn [ctx]
|
||||||
"Missing text to render.")
|
(:error ctx))
|
||||||
:handle-not-found
|
:handle-not-found
|
||||||
(fn [_]
|
(fn [ctx]
|
||||||
"Font not found."))
|
(:error ctx)))
|
||||||
|
|
||||||
(register-routes api-text-routes
|
(register-routes api-text-routes
|
||||||
(ANY "/api/text" {params :params} (render-text params)))
|
(ANY "/api/text" {params :params} (render-text params)))
|
||||||
|
|
Reference in a new issue