From 6da8abfb397eeaa2eed5675a9cd040ca3790a4a8 Mon Sep 17 00:00:00 2001 From: gered Date: Thu, 3 Apr 2014 22:23:03 -0400 Subject: [PATCH] better error (for now) when a non-GIF image is specified not yet ideal handling like how the normal image handling is done --- src/toascii/routes/api/image.clj | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/toascii/routes/api/image.clj b/src/toascii/routes/api/image.clj index 8e9de62..d939ac9 100644 --- a/src/toascii/routes/api/image.clj +++ b/src/toascii/routes/api/image.clj @@ -1,5 +1,6 @@ (ns toascii.routes.api.image - (:import (java.awt.image BufferedImage)) + (:import (java.awt.image BufferedImage) + (javax.imageio IIOException)) (:require [clojure.string :as str] [liberator.core :refer [defresource]] [compojure.core :refer [ANY]] @@ -59,7 +60,10 @@ (fn [ctx] (let [color? (or (nil? 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 (fn [ctx] (:error ctx))