linvi / tweetinvi

Tweetinvi, an intuitive Twitter C# library for the REST and Stream API. It supports .NET, .NETCore, UAP (Xamarin)...
MIT License
1.01k stars 220 forks source link

Authenticated user returns null result on expired token instead of throwing exception. #706

Open svncsvr opened 6 years ago

svncsvr commented 6 years ago

This is how I acquire an authenticated user to save a few requests for the sake of speed

var authenticatedUser = User.GetAuthenticatedUser(new TwitterCredentials(token.AppKey, token.AppSecret, token.Token, token.TokenSecret));

I am storing these authenticated users in a dictionary.Today I tried revoking application access to my twitter test account manually on their website.After I revoke application access and try using this authenticated user to get timeline, instead of throwing exception it returns null ( I already turned swallow exceptions switched off and made sure exception handling is actually working.)

Would it be possible to throw exceptions in this case as well or will I have to remove my cache mechanism to catch 401 errors and mark locally stored token expired.

linvi commented 6 years ago

If the ExceptionHandler is deactivated then it is a bug.

I will have a look into it.

Thanks for reporting it.

riccardotreso commented 6 years ago

Hi @svncsvr , try to set the propery ExceptionHandler.SwallowWebExceptions = false

let me know

svncsvr commented 6 years ago

Hi Riccardo, I already set it to false.The problem only arises If I store AuthenticatedUser instance with a valid access token in a dictionary for caching purpose and try to use it again (acquired from the cache I am not creating a fresh instance and I revoked the app's access to my twitter account so the token must be invalidated) instead of throwing an exception lets say for timeline calls, it returns null.

Tweetinvi version : 2.1.0

svncsvr commented 6 years ago

Is there any news on this.I might wanna look into source code and try to figure out what the problem is if there aren't a fix for the this issue.

linvi commented 6 years ago

No news on my side for now, I am currently trying to focus on the Twitter deadline of August 16.

JoshKeegan commented 5 years ago

Do you read and write from the dictionary on the same thread? I think the Exception Handler's settings are stored per-thread, so if reading the user out of the dictionary on another thread, you'd need to set ExceptionHandler.SwallowWebExceptions = false; again.

janwytze commented 5 years ago

I'm having the same problem even when I add ExceptionHandler.SwallowWebExceptions = false; before every Tweetinvi call it won't throw anything... I'm using the Async classes. Also ExceptionHandler.GetLastException() is always empty...

UPDATE Never mind https://github.com/linvi/tweetinvi/pull/770 should fix this