Streaming Backoff Strategy with Tweetinvi

Aug 1, 2014 at 12:51 PM
Edited Aug 1, 2014 at 1:52 PM
Hello,

I'm trying to implement backoff strategies when reconnecting a stream but I can't see the error codes returned by twitter when the stream is stopped. I've tried the ExceptionHandler GetLastException and GetException methods but they both return nothing.

The only exception I get is on the event args but that doesn't tell me much (also the disconnect message is null).

Can you please help me out with this; have a deadline to meet and this is the only thing holding me back.

Thanks in advance!
Editor
Aug 1, 2014 at 1:15 PM
Edited Aug 1, 2014 at 1:18 PM
var ts = Stream.CreateFilteredStream();
ts.StreamStopped += (sender, args) => Console.WriteLine("Exception: {0}", args.Exception.Message);
You can get the exception from the StreamStopped event args. Hope this works for you.

Edit: Oh... sorry I just saw this doesn't work well in your case. I'd wait for linvi to chime in.
Aug 3, 2014 at 9:45 PM
Edited Aug 3, 2014 at 9:53 PM
ExceptionHandler.WebExceptionReceived += (sender, args) =>
            {
                  var exception = (ITwitterException) args.Value;
                  var statusCode = exception.StatusCode;
                  // etc etc
            }
That's what I use. Covers all bases.
Marked as answer by madol on 8/4/2014 at 1:37 AM
Coordinator
Aug 4, 2014 at 12:29 AM
Edited Aug 4, 2014 at 12:30 AM
Hello there,

Would you please try to use the ExceptionHandler to generate a detailed Exception.
var twitterException = ExceptionHandler.GenerateTwitterException(webException, string.Empty);
Please let me know if this give you any additional information concerning your problem.
Regards,
Linvi
Aug 4, 2014 at 9:28 AM
Edited Aug 4, 2014 at 9:32 AM
adaam2 wrote:
``` ExceptionHandler.WebExceptionReceived += (sender, args) =>
        {
              var exception = (ITwitterException) args.Value;
              var statusCode = exception.StatusCode;
              // etc etc
        }


This works excellently, thanks Adam :)
Aug 4, 2014 at 9:31 AM
linvi wrote:
var twitterException = ExceptionHandler.GenerateTwitterException(webException, string.Empty);
The ExceptionHandler class doesn't have any definition for GenerateTwitterException; is this in a specific version (I'm using 0.9.2.0)
Coordinator
Aug 4, 2014 at 10:28 AM
I am happy to see that your problem has been fixed. But please always try to upgrade to the latest version as many new features are added to help the developers.

Linvi