hmil / RosHTTP

Unified Scala.js + Scala HTTP client API
MIT License
126 stars 24 forks source link

Empty error bodys throw null pointer exceptions #31

Closed easel closed 8 years ago

easel commented 8 years ago

Try load load a page that returns a 404 without any page content.

You'll get an exception something like this:

[info]   Cause: fr.hmil.roshttp.HttpNetworkError: java.lang.NullPointerException
[info]   at fr.hmil.roshttp.HttpDriver$$anonfun$send$1.apply(HttpDriver.scala:23)
[info]   at fr.hmil.roshttp.HttpDriver$$anonfun$send$1.apply(HttpDriver.scala:16)
[info]   at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
[info]   at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
[info]   at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
[info]   at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
[info]   at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
[info]   at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
[info]   at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
[info]   ...
[info]   Cause: java.lang.NullPointerException:
[info]   at fr.hmil.roshttp.tools.io.IO$.loop$3(IO.scala:78)
[info]   at fr.hmil.roshttp.tools.io.IO$.pipe(IO.scala:84)
[info]   at fr.hmil.roshttp.tools.io.IO$.readInputStreamToByteArray(IO.scala:69)
[info]   at fr.hmil.roshttp.HttpDriver$.fr$hmil$roshttp$HttpDriver$$readResponse(HttpDriver.scala:63)
[info]   at fr.hmil.roshttp.HttpDriver$$anonfun$send$1$$anonfun$apply$1.apply(HttpDriver.scala:19)
[info]   at fr.hmil.roshttp.HttpDriver$$anonfun$send$1$$anonfun$apply$1.apply(HttpDriver.scala:17)
[info]   at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$2$$anon$4.block(ExecutionContextImpl.scala:48)
[info]   at scala.concurrent.forkjoin.ForkJoinPool.managedBlock(ForkJoinPool.java:3640)
[info]   at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$2.blockOn(ExecutionContextImpl.scala:45)
[info]   at scala.concurrent.package$.blocking(package.scala:123)
easel commented 8 years ago

For reference, I have a hunch this issue is similar if not the same, but on the scala.js side:

https://github.com/scala-js/scala-js/issues/2558

hmil commented 8 years ago

Thank you for pointing this out.

I was not able to reproduce the bug. Could you tell me which version of java you are running and which jdk you are using (oracle / openJDK)?

hmil commented 8 years ago

Also it would be great if you could write a test case for your bug. I just realized I did not include development guidelines in this repo. Those will come soon with instructions for testing.

easel commented 8 years ago

How do I run the tests? They are trying to talk to something on port 3000 that I don't have ...

easel commented 8 years ago

I'm on oracle jdk8_102 on mac.

hmil commented 8 years ago

Here you go (you can rebase on master btw). I am using a Node.js server to test edge cases in a controlled environment.

easel commented 8 years ago

Ok I pushed a new version with a test that fails if you uncomment the fix.

hmil commented 8 years ago

Fix published in v1.0.1. Thank you for your contribution! :+1:

easel commented 8 years ago

Thanks for the merge!