From 01eb85c7dc449aef5bf7562f28eb50887b5f20c5 Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 6 Apr 2014 17:06:39 -0400 Subject: [PATCH] fix for trying to retrieve ascii art under a name which returns none --- src/toascii/models/db.clj | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/toascii/models/db.clj b/src/toascii/models/db.clj index 346ae6e..b5819de 100644 --- a/src/toascii/models/db.clj +++ b/src/toascii/models/db.clj @@ -56,10 +56,12 @@ (throw (new IndexOutOfBoundsException))))) (defn get-random-ascii-art [name] - (->> (couch/get-view-with-db (db-library) "list" "ids" {:key name}) - (rand-nth) - :value - (get-ascii-art))) + (let [results (couch/get-view-with-db (db-library) "list" "ids" {:key name})] + (if (seq results) + (->> results + (rand-nth) + :value + (get-ascii-art))))) (defn get-art-count [] (->> (couch/get-view-with-db (db-library) "list" "count")