Skip to content

Commit 1378981

Browse files
committed
feat: enhance error handling for calendar fetch failures
- Added specific handling for 404 errors in CalendarService to provide a user-friendly hint when the calendar feed is not found. - Updated TrayContext to display the last fetch error message in the balloon tip instead of a generic message. - Introduced a new UI text constant for the calendar fetch error title.
1 parent ccd9876 commit 1378981

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/ComingUpNextTray/Services/CalendarService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ public async Task<IReadOnlyList<CalendarEntry>> FetchWithErrorsAsync(Uri calenda
183183
{
184184
hint = " Redirected location may require authentication.";
185185
}
186+
else if (code == 404)
187+
{
188+
hint = " Calendar feed not found (404). Check the calendar URL.";
189+
}
186190
else if (code == 401 || code == 403)
187191
{
188192
hint = " Calendar feed appears to require authentication (401/403).";
@@ -237,6 +241,10 @@ public async Task<IReadOnlyList<CalendarEntry>> FetchIfChangedWithErrorsAsync(Ur
237241
{
238242
hint = " Redirected location may require authentication.";
239243
}
244+
else if (code == 404)
245+
{
246+
hint = " Calendar feed not found (404). Check the calendar URL.";
247+
}
240248
else if (code == 401 || code == 403)
241249
{
242250
hint = " Calendar feed appears to require authentication (401/403).";

src/ComingUpNextTray/TrayContext.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,10 @@ private async Task RefreshAndUpdateUiAsync()
391391
{
392392
// Show a one-time balloon if calendar URL exists but fetch failed.
393393
string url = this.app.GetCalendarUrlForUi();
394-
if (!string.IsNullOrWhiteSpace(url))
394+
string? fetchErr = this.app.GetLastFetchErrorForUi();
395+
if (!string.IsNullOrWhiteSpace(url) && !string.IsNullOrWhiteSpace(fetchErr))
395396
{
396-
this.ShowErrorBalloon();
397+
this.ShowErrorBalloon(fetchErr);
397398
}
398399
}
399400
}
@@ -404,12 +405,12 @@ private async Task RefreshAndUpdateUiAsync()
404405
}
405406

406407
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "Using centralized UiText constants; localization pending.")]
407-
private void ShowErrorBalloon()
408+
private void ShowErrorBalloon(string message)
408409
{
409410
try
410411
{
411-
this.notifyIcon.BalloonTipTitle = UiText.ConfigErrorTitle;
412-
this.notifyIcon.BalloonTipText = UiText.ConfigErrorMessage;
412+
this.notifyIcon.BalloonTipTitle = UiText.FetchErrorTitle;
413+
this.notifyIcon.BalloonTipText = message;
413414
this.notifyIcon.ShowBalloonTip(3000);
414415
}
415416
catch (System.ComponentModel.Win32Exception)

src/ComingUpNextTray/UiText.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ internal static class UiText
6565
/// <summary>Body text for configuration error message box.</summary>
6666
internal const string ConfigErrorMessage = "Config file malformed. Renamed to config.json.invalid.";
6767

68+
/// <summary>Title for calendar/network fetch error balloon tips.</summary>
69+
internal const string FetchErrorTitle = "Calendar Error";
70+
6871
/// <summary>Tooltip or UI text when no calendar configured.</summary>
6972
internal const string NoCalendarConfigured = "No calendar URL configured";
7073

0 commit comments

Comments
 (0)