How do I get a more accurate error message from the http.dart library when the server is not available?

Viewed 197

I'm using Flutter Web and therefore the http.dart library, not the dart:io library. I make a post request to my webserver and I would like to get a good error message when the server isn't running at all.

I catch the ClientException, but with .toString() the only thing I get is "XMLHttpRequest error.".

The response object is null, so I don't get any more detail from there.

Is it maybe related to the limited functionality of the library, because it is limited by the web browser?

I would want something like "Server cannot be reached." or even more details.

http.Response resp;
try {
    resp = await client.post(host, headers: {"Content-Type": "application/json"}, body: "bla");
} on http.ClientException catch (err, stacktrace) {
    print(err.toString());    
    print(stacktrace.toString());
}

Thanks for your help!

0 Answers
Related