Error Handling Mechanism

Oct 31, 2013 at 8:46 PM
Hi I would like to know if Tweetinvi has any specific error handling mechanism. For example, in TweetSharp, you can do
TwitterError error = twitterService.Response.Error;
 if (error != null)
                        if (!twitterService.Response.StatusCode.ToString().Equals("429"))
Is there anything similar from Tweetinvi that I can use to check error in Twitter Response? Please advise.

Oct 31, 2013 at 10:07 PM

The error handling is done thanks to the class called TwitterContext.
There are some examples in the Exception Management Region located in Examplinvi.

You can also find some examples in the documentation (Tools -> Twitter Context - Manage Exceptions).

The TwitterContext provide more features than just saving the last exception, it stores all the Exceptions and provide additional information to the Exception sent by Twitter.

When an Exception is thrown from Twitter, the TwitterContext will catch it and inform the user that the action has not been successful.
ITokenUser u;
if (!context.TryInvokeAction(() => new TokenUser(new Token("", "", "", "")), out u))
    // At this point you must handle the exception!
You can access various information from the LastTwitterException like the TwitterErrorWebDescription, Status Code and Message.
Link to TwitterException class.

The action you are passing can be either contain a single operation or multiple operations.

Hope this helps.
Marked as answer by linvi on 11/12/2013 at 2:49 AM