diff --git a/lib/core/errors.dart b/lib/core/errors.dart index e0c3e21f4..3c267a714 100644 --- a/lib/core/errors.dart +++ b/lib/core/errors.dart @@ -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; } diff --git a/test/core/network/network_provider_test.dart b/test/core/network/network_provider_test.dart index d93d45901..196431588 100644 --- a/test/core/network/network_provider_test.dart +++ b/test/core/network/network_provider_test.dart @@ -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;