Skip to content

Commit 775ba51

Browse files
authored
fix: no internet connection handler (#265) Resolves #262
* fetcher - error handler | prevent internet connection related error from being reported * fcm - offline | notification setup disable if device offline * Fetcher - HTTP error handler | move the internet connection check at the top
1 parent 1d534c8 commit 775ba51

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

App/Services/Fetcher.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public async Task<Collection<Source>> GetSources()
8383
{
8484
return Fetcher.Sources = await WebService.Get<Collection<Source>>(controller: "sources",
8585
action: "getAll",
86-
unSuccessCallback: e => _ = HandleHttpException(e));
86+
unSuccessCallback: e => _ = HandleHttpException(e));
8787
}
8888
/// <summary>
8989
/// Get the feed of an article
@@ -429,10 +429,16 @@ public void SaveUserInfo(User user)
429429
/// <exception cref="Exception"></exception>
430430
private async Task HandleHttpException(HttpResponseMessage err)
431431
{
432+
string errMsg = await err.Content.ReadAsStringAsync();
433+
434+
if (Connectivity.Current.NetworkAccess != NetworkAccess.Internet
435+
&& (errMsg.Contains("internet connection") || errMsg.Contains("Connection failure")))
436+
// If the error is being thrown because there is no internet: there is no point reporting it
437+
return;
432438
#if DEBUG
433-
throw new Exception(await err.Content.ReadAsStringAsync());
439+
throw new Exception(errMsg);
434440
#else
435-
SentrySdk.CaptureException(new Exception(await err.Content.ReadAsStringAsync()));
441+
SentrySdk.CaptureException(new Exception(errMsg));
436442
#endif
437443
}
438444

App/ViewModels/AppShellViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ public async Task UpdateDeals()
127127
/// </summary>
128128
public async Task NotificationSetup()
129129
{
130+
if (Connectivity.Current.NetworkAccess != NetworkAccess.Internet)
131+
return;
132+
130133
if ((await _firebasePushPermissions.GetAuthorizationStatusAsync() is not Plugin.FirebasePushNotifications.Model.AuthorizationStatus.Granted)
131134
&& Preferences.Get(_notificationKey, true))
132135
#if ANDROID

0 commit comments

Comments
 (0)