requests
requests copied to clipboard
Can't catch SocketException
Exception has occurred.
SocketException (SocketException: OS Error: Connection timed out, errno = 110, address = carlhung.mynetgear.com, port = 45396)
I can catch the returned result. but after a while, the simulator of android will crash with SocketException. my code:
try {
request = await Requests.post(
url + '/login',
headers: {'content-type': 'application/json'},
json: dic,
verify: false,
// timeoutSeconds: 5,
);
} catch (e) {
return {"result":"Connection Error: $e"};
}
do you have the stacktrace of where the exception is thrown?
please check in all places you call Requests
that you are using await
, if not it will cause this behavior
https://github.com/dart-lang/http/issues/160
I encounter the problem is more like that: https://stackoverflow.com/questions/57182940/unhandled-socket-exception-with-no-internet-connection-when-i-set-timeout-durati
can catch the timeoutException error. then, it will be returned. but after 15-20 sec, it throws socketException.
so, it throws twice. the first exception will be caught.
can we schedule some time to chat this weekend? mail me your info to [email protected]
hey, sorry. Do you use whatsapp? you can add me by my phone number which is +852 64616196 this weekend is chinese new year. You can text me anytime as coronavirus is scaring all hk people(I am from Hong Kong). so, I believe i will be available as no one wants to go out.
an update on this one? feel like this is an environmental issue.
closing due to inactivity. comment to reopen
I am using gsheets api to access a gsheet in my drive. i thought that when the internet is turned off then a pop up would appear on accessingvthe gsheet but am not able to handle the SocketException. https://github.com/dart-lang/http/issues/160 Some peopke have this issue but mine is still unresolved
Hello, I experience the exact same behavior. I use
import 'package:http/http.dart' as http;
import 'dart:io';
and when
http.Response response = await _client
.get(dataURL, headers: _standardHeaders)
.timeout(const Duration(seconds: 20));
runs into a timeout because the server is down
} on SocketException catch (e) {
return (Left(e));
} catch (e) {
return (Left(e));
}
catches the timeout exception first, what is perfect!
But then, after some time the client throws
Exception has occurred.
SocketException (SocketException: OS Error: Connection timed out, errno = 110, address = 192.168.178.62, port = 44850)
in io_client.dart at
var ioRequest = (await _inner.openUrl(request.method, request.url))
This is not catched. The Client (Android Emulator) crashes and code execution stops.
@akreienbring thanks for sharing! can you help fixing this?
Possible same issue https://stackoverflow.com/questions/66034255/http-get-not-fall-into-than-or-catcherror-block