brian-gates/cypher-stream — pull request #5 by aseemk (2014-08-02 19:52:49+00:00)
Title: Emit proper Error instances on non-query errors

E.g. DNS lookup failed, or the base URL led to a 404.

Currently, `{statusCode, body, jsonBody, thrown}` objects are emitted instead, which have no `message`, no `stack`, etc.

Looking at Oboe.js, `thrown` is the actual `Error` instance, if there is one:

https://github.com/jimhigson/oboe.js/blob/v1.15.1/dist/oboe-node.js#L2003-L2014
https://github.com/jimhigson/oboe.js/blob/v1.15.1/dist/oboe-node.js#L1115-L1138

So this PR now uses that if available.

But as you can see, in the case of HTTP errors (e.g. the aforementioned 404), there isn't an `Error` instance at all. So this PR now creates one in that case.

For backwards-compatibility, this PR maintains the other properties on the `Error` instance either way (`statusCode`, `body`, `jsonBody`, but not a circular `thrown` reference).