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

Handle RequestException #747

Merged
merged 1 commit into from
Aug 31, 2024
Merged
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 GrammarNazi.Core/Services/CatchExceptionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Mail;
using System.Net.Sockets;
using Telegram.Bot.Exceptions;
using Tweetinvi.Exceptions;
Expand Down Expand Up @@ -55,12 +56,27 @@
HandleTwitterException(twitterException, githubIssueSection);
break;

case RequestException requestException:
HandleRequestException(requestException, githubIssueSection);
break;

default:
HandleGeneralException(exception, githubIssueSection);
break;
}
}

private void HandleRequestException(RequestException requestException, GithubIssueLabels githubIssueSection)
{
if (requestException.GetInnerExceptions().Any(x => x.Message?.ContainsAny("Operation canceled", "response ended prematurely") == true))
{
_logger.LogWarning(requestException, requestException.Message);
return;
}

HandleGeneralException(requestException, githubIssueSection);
}

private void HandleTwitterException(TwitterException twitterException, GithubIssueLabels githubIssueSection)
{
if (twitterException.TwitterDescription.Contains("Try again later") || twitterException.TwitterDescription.Contains("Timeout limit"))
Expand Down Expand Up @@ -99,7 +115,7 @@
{
if (requestException.StatusCode == HttpStatusCode.BadGateway)
{
_logger.LogWarning("Bad Gateway", requestException);

Check warning on line 118 in GrammarNazi.Core/Services/CatchExceptionService.cs

View workflow job for this annotation

GitHub Actions / build

Number of parameters supplied in the logging message template do not match the number of named placeholders (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2017)
return;
}

Expand Down
Loading