How to retrieve exact reason of the error from async HttpRequest?

dart

Solution

Unfortunately, there is no property to report the error as detailed as you'd like. The reason is that JavaScript doesn't support this.

There are the properties `status` and `statusText` on the `HttpRequest` object (which you could get from your `HttpRequestProgressEvent` with `evt.target`, but those represent HTTP status codes. Every other error has the status code 0 - request failed. This could be anything, and the only place to look at is the browser's console, because this is an Exception thrown by the browser.

If your request was synchronous, you could surround the `send()` with a try-catch. If your request is async, this won't work.

Problem

I am trying to figure out how to find out exact reason of (async) HttpRequest (from 'dart:html') failure, and, to be honest, I am a bit lost here. The onError callback receives only HttpRequestProgressError object, which doesn't have anything useful, and the HttpRequest object itself has "status" set to "0" in case of failure, even console shows "Failed to load resource" with no details. What I want is to know the exact reason - like "connection refused" or "host name not resolved". Is this possible at all? Thank you!

Original source