Skip to content

Commit

Permalink
Add HttpRequestException expected exception handling (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkbennett authored Sep 11, 2024
1 parent b6ca3c4 commit 8664939
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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

0 comments on commit 8664939

Please sign in to comment.