mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-29 09:20:56 +01:00
Treat raw OSErrors as network errors
On iOS, dart:io fails setting TCP_NODELAY on a connection that was already reset and throws a plain OSError instead of a SocketException. The reachability probe rethrew it and the app showed an error dialog. Closes #1397
This commit is contained in:
@@ -65,6 +65,8 @@ ErrorSeverity classifyError(Object? error) {
|
||||
bool isNetworkError(Object e) {
|
||||
return e is http.ClientException ||
|
||||
e is SocketException ||
|
||||
// Raw from socket options, e.g. TCP_NODELAY on a reset connection on iOS
|
||||
e is OSError ||
|
||||
e is HandshakeException ||
|
||||
e is TimeoutException;
|
||||
}
|
||||
|
||||
@@ -645,6 +645,21 @@ void main() {
|
||||
|
||||
expect(probeCount, greaterThan(afterInit));
|
||||
});
|
||||
group('default reachability check', () {
|
||||
final probeUri = Uri.parse('https://wger.example/api/v2/version/');
|
||||
|
||||
test('a raw OSError from the socket counts as unreachable', () async {
|
||||
// iOS fails setting TCP_NODELAY on an already reset connection, which
|
||||
// dart:io throws as OSError instead of SocketException (flutter#1397)
|
||||
final result = await http.runWithClient(
|
||||
() => originalReachability(probeUri, null, const Duration(seconds: 1)),
|
||||
() => MockClient((_) => throw const OSError('Invalid argument', 22)),
|
||||
);
|
||||
|
||||
expect(result.reachable, isFalse);
|
||||
});
|
||||
});
|
||||
|
||||
group('ReachabilityReportingClient', () {
|
||||
late _RecordingNetworkStatus status;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user