better error (for now) when a non-GIF image is specified

not yet ideal handling like how the normal image handling is done
This commit is contained in:
Gered 2014-04-03 22:23:03 -04:00
parent 1998672258
commit 6da8abfb39

View file

@ -1,5 +1,6 @@
(ns toascii.routes.api.image (ns toascii.routes.api.image
(:import (java.awt.image BufferedImage)) (:import (java.awt.image BufferedImage)
(javax.imageio IIOException))
(:require [clojure.string :as str] (:require [clojure.string :as str]
[liberator.core :refer [defresource]] [liberator.core :refer [defresource]]
[compojure.core :refer [ANY]] [compojure.core :refer [ANY]]
@ -59,7 +60,10 @@
(fn [ctx] (fn [ctx]
(let [color? (or (nil? color) (let [color? (or (nil? color)
(parse-boolean color))] (parse-boolean color))]
(gif->ascii (:image ctx) (parse-int width) color?))) (try
(gif->ascii (:image ctx) (parse-int width) color?)
(catch IIOException ex
(throw (new Exception "Invalid GIF image."))))))
:handle-malformed :handle-malformed
(fn [ctx] (fn [ctx]
(:error ctx)) (:error ctx))