         (is (= 2 (:count result)))
         (is (= search-data (:results result)))))
 
+    (testing "json request with invalid page returns error"
+      (let [resp (do-search-with-page :json "test" "a" {:throw-exceptions false})
+            result (json/parse-string (:body resp) true)]
+        (prn resp)
+        (is (= 400 (:status resp)))
+        (is (= "application/json" (help/get-content-type resp)))
+        (is (not (nil? (:error result))))
+        (is (not (nil? (:error-id result))))))
+
     (testing "invalid query syntax returns error"
       (let [resp (do-search :json "test+AND" {:throw-exceptions false})
             result (json/parse-string (:body resp) true)]

        (is (= 200 (:status resp)))
        (is (= "text/html" (help/get-content-type resp)))))

    (testing "unknown format request returns html" ;; debatable behavior
      (let [resp (do-search :ham "test")]
        (is (= 200 (:status resp)))

        query
        (name fmt))
    (client/get opts)))

(defn do-search-with-page [fmt query page & [opts]]
  (-> (format "http://localhost:%s/search?q=%s&format=%s&page=%s"
        help/test-port
        query
        (name fmt)
        page)
      (client/get opts)))

(deftest search-test
  (let [base-data {:description "foo" :version "1.0"}
