Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HttpRequestException expected exception handling #443

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/GitHubExtension/DataManager/GitHubDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ private async Task UpdateDataStoreAsync(DataStoreOperationParameters parameters,
PruneObsoleteData();
SetLastUpdatedInMetaData();
}
catch (HttpRequestException httpEx)
{
// HttpRequestExceptions can happen when internet connection is
// down or various other network issues.
_log.Warning($"Http Request Exception: {httpEx.Message}");
tx.Rollback();

// Rethrow so clients can catch/display appropriate UX.
throw;
}
catch (Exception ex)
{
_log.Error(ex, $"Failed Updating DataStore for: {parameters}");
Expand Down Expand Up @@ -331,6 +341,12 @@ private async Task UpdateDataForRepositoryAsync(DataStoreOperationParameters par
PruneObsoleteData();
SetLastUpdatedInMetaData();
}
catch (HttpRequestException)
{
// Higher layer will catch and log this. Suppress logging an error for this to keep log clean.
tx.Rollback();
throw;
}
catch (Exception ex)
{
// This is for catching any other unexpected error as well as any we throw.
Expand Down
9 changes: 9 additions & 0 deletions src/GitHubExtension/DataManager/GitHubDataManagerUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ public static async Task Update()
{
await UpdateDeveloperPullRequests();
}
catch (HttpRequestException httpEx)
{
// HttpRequestExceptions can happen when internet connection is
// down or various other network issues unrelated to this update.
// This is not an error in the extension or anything we can
// address. Log a warning so it is understood why the update did
// not occur, but otherwise keep the log clean.
_log.Warning($"Http Request Exception: {httpEx.Message}");
}
catch (Exception ex)
{
_log.Error(ex, "Update failed unexpectedly.");
Expand Down
Loading