From 73da0e14781dab4d5b026fefebba96945b5040fe Mon Sep 17 00:00:00 2001 From: Daniel Pfeiffer Date: Tue, 23 Jul 2024 15:32:46 -0500 Subject: [PATCH] Improves offline message detection on Android --- Float.Core/Extensions/Exception.extensions.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Float.Core/Extensions/Exception.extensions.cs b/Float.Core/Extensions/Exception.extensions.cs index 107b440..1b96f03 100644 --- a/Float.Core/Extensions/Exception.extensions.cs +++ b/Float.Core/Extensions/Exception.extensions.cs @@ -37,6 +37,13 @@ public static bool IsOfflineException(this Exception e) return true; } + // On Android, the message might literally be "Connection failure" + // (see https://github.com/dotnet/android/blob/688245d397097fbc8e70fd291abe11143f1c3553/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs#L577) + if (e.Message == "Connection failure") + { + return true; + } + // we sometimes get a webexception status of NameResolutionFailure that we don't have access to, but its enum value is one if (e.InnerException is WebException webException && ((int)webException.Status == 1 || webException.Status == WebExceptionStatus.ConnectFailure)) {