2

Hi I tried to catch a socketException when the server I am consulting is not available, I tried with try{}catch{}, catchError and timeout, but it doesn't work

I need that if some time passes that the server does not respond, that it already stops waiting for it

The error is :

enter image description here

and I tried something like this

enter image description here

JUAN ALVARES
  • 75
  • 11
  • Check this out: https://stackoverflow.com/questions/51487818/set-timeout-for-httpclient-get-request – Shayan Feb 25 '22 at 07:31

1 Answers1

-2

You are probably giving the code the wrong URL. Maybe this link will help You. Link. If You could just type in the URL and If You are using Python with flask or Django, or Node.js, that would help tremendously.

Update:

In the part where You say

final resp = await http.get(url).catchError({(onError) => print(onError)});

You should change it to this:

final resp = await http.get(url).catchError((onError) {
    print(onError); 
    return null;
});

Because You are catching the Error in the response and only printing it. You should return null; and escape that function.

I hope this helped.

  • 1
    I'm putting it right, but what I want is that when the server is off, I can catch that error to show some "connection error" message – JUAN ALVARES Jan 10 '21 at 04:34