From 1d5df9a83b54e73c2fad4479f50f22081dd3fece Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Fri, 29 Jan 2021 23:10:02 -0500 Subject: [PATCH] make user retrieval more resilient --- src/BirdsiteLive.Twitter/TwitterTweetsService.cs | 8 ++++---- src/BirdsiteLive.Twitter/TwitterUserService.cs | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs index e67b125..38d1d68 100644 --- a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs +++ b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs @@ -59,13 +59,13 @@ namespace BirdsiteLive.Twitter public ExtractedTweet[] GetTimeline(string username, int nberTweets, long fromTweetId = -1) { TweetinviConfig.CurrentThreadSettings.TweetMode = TweetMode.Extended; - - var user = _twitterUserService.GetUser(username); - if (user.Protected) return new ExtractedTweet[0]; - + var tweets = new List(); try { + var user = _twitterUserService.GetUser(username); + if (user == null || user.Protected) return new ExtractedTweet[0]; + if (fromTweetId == -1) { var timeline = Timeline.GetUserTimeline(user.Id, nberTweets); diff --git a/src/BirdsiteLive.Twitter/TwitterUserService.cs b/src/BirdsiteLive.Twitter/TwitterUserService.cs index e7d44c3..e8729a6 100644 --- a/src/BirdsiteLive.Twitter/TwitterUserService.cs +++ b/src/BirdsiteLive.Twitter/TwitterUserService.cs @@ -38,7 +38,11 @@ namespace BirdsiteLive.Twitter { user = User.GetUserFromScreenName(username); _statisticsHandler.CalledUserApi(); - if (user == null) return null; + if (user == null) + { + _logger.LogWarning("User {username} not found", username); + return null; + } } catch (Exception e) {