Repository: clj-commons/aleph (clojure)

Issue:
java.lang.IllegalArgumentException: cannot treat nil as HTTP response for request to ''  
This is an issue with the request, but probably Aleph should be able to handle it without an exception. Is that correct?

```
SEVERE: error in HTTP handler                                                                                                                                                                          
java.lang.IllegalArgumentException: cannot treat nil as HTTP response for request to ''  
 at aleph.http.server$invalid_value_response.invokeStatic(server.clj:132) 
 at aleph.http.server$invalid_value_response.invoke(server.clj:129) 
 at aleph.http.server$handle_request$fn__20360$fn__20361.invoke(server.clj:185) 
 at manifold.deferred$fn__17496$chain_SINGLEQUOTE____17517.invoke(deferred.clj:750) 
 at manifold.deferred$fn__17496$subscribe__17497$fn__17502.invoke(deferred.clj:716) 
 at manifold.deferred.Listener.onSuccess(deferred.clj:219) 
 at manifold.deferred.Deferred$fn__17350.invoke(deferred.clj:396) 
 at manifold.deferred.Deferred.success(deferred.clj:396) 
 at manifold.deferred$success_BANG_.invokeStatic(deferred.clj:243) 
 at manifold.deferred$success_BANG_.invoke(deferred.clj:240) 
 at manifold.deferred$catch_SINGLEQUOTE_$fn__17580.invoke(deferred.clj:959) 
 at manifold.deferred.Listener.onSuccess(deferred.clj:219) 
 at manifold.deferred.Deferred$fn__17350.invoke(deferred.clj:396) 
 at manifold.deferred.Deferred.success(deferred.clj:396) 
 at manifold.deferred$success_BANG_.invokeStatic(deferred.clj:243) 
 at manifold.deferred$success_BANG_.invoke(deferred.clj:240) 
 at manifold.deferred$fn__17496$chain_SINGLEQUOTE____17517.invoke(deferred.clj:737) 
 at manifold.deferred$fn__17496$subscribe__17497$fn__17498.invoke(deferred.clj:710) 
 at manifold.deferred.Listener.onSuccess(deferred.clj:219) 
 at manifold.deferred.Deferred$fn__17350.invoke(deferred.clj:396) 
 at manifold.deferred.Deferred.success(deferred.clj:396) 
 at manifold.deferred$success_BANG_.invokeStatic(deferred.clj:243) 
 at manifold.deferred$success_BANG_.invoke(deferred.clj:240) 
 at aleph.http.server$handle_request$fn__20345$f__16979__auto____20346.invoke(server.clj:153) 
 at clojure.lang.AFn.run(AFn.java:22) 
 at io.aleph.dirigiste.Executor$Worker$1.run(Executor.java:62) 
 at manifold.executor$thread_factory$reify__16871$f__16872.invoke(executor.clj:36) 
 at clojure.lang.AFn.run(AFn.java:22) 
 at java.lang.Thread.run(Thread.java:745) 
Jul 02, 2016 11:22:15 AM aleph.http.server invoke 
```

Pull request description:
Closes #264

Patch:
diff --git a/src/aleph/http/server.clj b/src/aleph/http/server.clj
index 353cf4ff..621e5cb8 100644
--- a/src/aleph/http/server.clj
+++ b/src/aleph/http/server.clj
@@ -147,11 +147,16 @@
 
 (defn invalid-value-exception [req x]
   (IllegalArgumentException.
-   (str "cannot treat "
+   (str "Cannot treat "
         (pr-str x)
-        " as HTTP response for request to '"
-        (:uri req)
-        "'")))
+        (when (some? x) (str " of " (type x)))
+        (format " as a response to '%s'.
+Ring response expected.
+
+Example: {:status 200
+          :body \"hello world\"
+          :headers \"text/plain\"}"
+                (pr-str (select-keys req [:uri :request-method :query-string :headers]))))))
 
 (defn handle-request
   [^ChannelHandlerContext ctx


Test patch:
diff --git a/test/aleph/http/server_test.clj b/test/aleph/http/server_test.clj
new file mode 100644
index 00000000..b23310d4
--- /dev/null
+++ b/test/aleph/http/server_test.clj
@@ -0,0 +1,20 @@
+(ns aleph.http.server-test
+  (:require [aleph.http.server :as server]
+            [clojure.string    :as str]
+            [clojure.test      :refer [deftest is]]))
+
+(deftest test-invalid-value-exception
+  (is (str/starts-with?
+       (ex-message (server/invalid-value-exception nil nil))
+       "Cannot treat nil as a response to '{}'.\nRing response expected."))
+  (is (str/starts-with?
+       (ex-message (server/invalid-value-exception nil false))
+       "Cannot treat false of class java.lang.Boolean as a response to '{}'.\nRing response expected."))
+  (is (str/starts-with?
+       (ex-message (server/invalid-value-exception {:uri "http://localhost/hello"
+                                                    :request-method :get} nil))
+       "Cannot treat nil as a response to '{:uri \"http://localhost/hello\", :request-method :get}'.\nRing response expected."))
+  (is (str/starts-with?
+       (ex-message (server/invalid-value-exception {:uri "http://localhost/hello"
+                                                    :request-method :get} "hello"))
+       "Cannot treat \"hello\" of class java.lang.String as a response to '{:uri \"http://localhost/hello\", :request-method :get}'.\nRing response expected.")))