Skip to content

Commit

Permalink
TwitchApi error handling: log actual twitch responses on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Felk committed Oct 15, 2024
1 parent 47a7052 commit d176d31
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions TPP.Core/TwitchApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,21 @@ private async Task<T> Retrying<T>(TwitchApiProvider apiProvider, Func<TwitchAPI,
}
catch (HttpResponseException ex)
{
string twitchResponse = await ex.HttpResponse.Content.ReadAsStringAsync();
switch ((int)ex.HttpResponse.StatusCode)
{
case 401:
// unexpectedly expired tokens are retryable if we successfully refresh the token.
_logger.LogDebug(ex, "Retryable TwitchAPI 401 auth error occurred: {Error}", twitchResponse);
await apiProvider.Invalidate();
return await action(await apiProvider.Get());
case >= 500 and < 600:
// issues on Twitch's end may be transient and often don't occurr a second time
_logger.LogDebug(ex, "Retryable TwitchAPI 500 server error occurred: {Error}", twitchResponse);
return await action(await apiProvider.Get());
default:
// otherwise, assume it's an actual error with our request and don't retry it
_logger.LogError(ex, "Unretryable TwitchAPI error occurred: {Error}", twitchResponse);
throw;
}
}
Expand Down

0 comments on commit d176d31

Please sign in to comment.