purescript-contrib / purescript-affjax

An asynchronous AJAX library built using Aff.
Apache License 2.0
122 stars 79 forks source link

Possible to get a more detailed error message in node? #130

Closed btrepp closed 5 years ago

btrepp commented 5 years ago

Is there any way to extract better errors when using with node XHR2?

Running via pulp run. Using attempt and purescript debug to print i get

Left { value0: Error: AJAX request failed: GET https://myserver at XMLHttpRequest.xhr.onerror (C:\VisualStudio_Projects\purescript\octopusexport\output\Affjax\foreign.js:57:17) at XMLHttpRequestEventTarget.dispatchEvent (C:\VisualStudio_Projects\purescript\octopusexport\node_modules\xhr2\lib\xhr2.js:64:18) at XMLHttpRequest._dispatchProgress (C:\VisualStudio_Projects\purescript\octopusexport\node_modules\xhr2\lib\xhr2.js:555:12) at XMLHttpRequest._onHttpRequestError (C:\VisualStudio_Projects\purescript\octopusexport\node_modules\xhr2\lib\xhr2.js:545:12) at ClientRequest. (C:\VisualStudio_Projects\purescript\octopusexport\node_modules\xhr2\lib\xhr2.js:414:24) at ClientRequest.emit (events.js:182:13) at TLSSocket.socketErrorListener (_http_client.js:391:9) at TLSSocket.emit (events.js:182:13) at emitErrorNT (internal/streams/destroy.js:82:8) at emitErrorAndCloseNT (internal/streams/destroy.js:50:3) }

Unfortunately this doesn't give any indication as to why the request failed, which makes it hard to fix. On this machine it could be auth, proxy, or tls errrors, but I'd like to be able to see what the root cause is.

Is this a xhr2 issue? Or is it possible to get more detail from affjax?

garyb commented 5 years ago

If this is the kind of error I think it is, it's equally bad in the browser - so it's not because of xhr2 specifically, it's just that if an XHR request fails entirely (that is to say, there's no response at all because the URI is invalid, or the server doesn't exist, etc.) there's basically no information provided about what went wrong.

You only get meaningful errors when there is actually some response for the request.

btrepp commented 5 years ago

I'd say that's exactly it. XHR is such a pain of an API. I wish it gave even a little bit more detail about what went wrong.

My root cause here is ultimately that affjax+xhr2 aren't using a http proxy, but I will raise a seperate issue about that