using System.Net; namespace ShareeBike.Repository.Exception { public static class WebExceptionHelper { /// Gets if a exception is caused by an error connecting to copri (LAN or mobile data off/ not reachable, proxy, ...). /// Expection to check. /// True if exception if caused by an connection error. public static bool GetIsConnectFailureException(this System.Exception exception) { #if !USCSHARP9 if (!(exception is WebException webException)) #else if (exception is not WebException webException) #endif { return false; } return webException.Status == WebExceptionStatus.ConnectFailure // Happens if WLAN and mobile data is off/ Router denies internet access/ ... || webException.Status == WebExceptionStatus.NameResolutionFailure // Happens sometimes when not WLAN and no mobil connection are available (bad connection in lift). || webException.Status == WebExceptionStatus.ReceiveFailure; // Happened when mobile was connected to WLAN } /// Gets if a exception is caused by clicking too fast. /// Expection to check. /// True if exception if caused by a fast click sequence. public static bool GetIsForbiddenException(this System.Exception exception) { #if !USCSHARP9 if (!(exception is WebException webException)) #else if (exception is not WebException webException) #endif { return false; } #if !USCSHARP9 if (!(webException?.Response is HttpWebResponse response)) #else if (webException?.Response is not HttpWebResponse response) #endif { return false; } return webException.Status == WebExceptionStatus.ProtocolError && response.StatusCode == HttpStatusCode.Forbidden; } } }