Exemple #1
0
 private static void ErrorHandler(object sender, PusherException error)
 {
     if ((int)error.PusherCode < 5000)
     {
         // Error recevied from Pusher cluster, use PusherCode to filter.
     }
     else
     {
         if (error is ChannelUnauthorizedException unauthorizedAccess)
         {
             // Private and Presence channel failed authorization with Forbidden (403)
         }
         else if (error is ChannelAuthorizationFailureException httpError)
         {
             // Authorization endpoint returned an HTTP error other than Forbidden (403)
         }
         else if (error is OperationTimeoutException timeoutError)
         {
             // A client operation has timed-out. Governed by PusherOptions.ClientTimeout
         }
         else if (error is ChannelDecryptionException decryptionError)
         {
             // Failed to decrypt the data for a private encrypted channel
         }
         else
         {
             // Handle other errors
         }
     }
 }
Exemple #2
0
 private void PusherError(object sender, PusherException error)
 {
     if (error != null)
     {
         Logger.Error(error, PusherServiceEvents.PusherError);
     }
 }
 private static void ValidateMemberRemovedEventHandlerException(PusherException error, int expectedNumMemberRemovedErrorEvents, int numMemberRemovedErrors, AutoResetEvent memberRemovedErrorEvent)
 {
     if (error is MemberRemovedEventHandlerException <FakeUserInfo> memberRemovedException)
     {
         bool errorValid = memberRemovedException.InnerException is InvalidOperationException;
         if (errorValid && string.IsNullOrWhiteSpace(memberRemovedException.MemberKey))
         {
             errorValid = false;
         }
         if (errorValid && memberRemovedException.Member == null)
         {
             errorValid = false;
         }
         if (errorValid && memberRemovedException.Member.name == null)
         {
             errorValid = false;
         }
         if (errorValid && memberRemovedException.PusherCode != ErrorCodes.MemberRemovedEventHandlerError)
         {
             errorValid = false;
         }
         if (errorValid)
         {
             if (numMemberRemovedErrors == expectedNumMemberRemovedErrorEvents)
             {
                 memberRemovedErrorEvent.Set();
             }
         }
     }
 }
Exemple #4
0
 /// <summary>
 /// входящая ошибка
 /// </summary>
 private void _pusher_Error(object sender, PusherException error)
 {
     if (LogMessageEvent != null)
     {
         LogMessageEvent(error.ToString(), LogMessageType.Error);
     }
 }
        public async Task PusherShouldErrorWhenDisconnectTimesOutAsync()
        {
            // Arrange
            AutoResetEvent     errorEvent      = new AutoResetEvent(false);
            PusherException    pusherException = null;
            AggregateException caughtException = null;

            Pusher pusher = await ConnectTestAsync().ConfigureAwait(true);

            _client = pusher;

            pusher.Error += (sender, error) =>
            {
                pusherException = error;
                errorEvent.Set();
            };

            /*
             *  This test requires two distinct threads to attempt to disconnect at the same time because
             *  it is the second thread that will timeout. The first thread will disconnect because the
             *  semaphore count for _disconnectLock is one and the count will be zero on the second thread.
             *  There are times on the build server when it fails to spin up two distinct threads.
             */
            // Act
            ((IPusher)pusher).PusherOptions.ClientTimeout = TimeSpan.FromTicks(1);

            // Try to generate the error multiple times as it does not always error the first time
            for (int attempt = 0; attempt < TimeoutRetryAttempts; attempt++)
            {
                int      numThreads = 2;
                Thread[] tasks      = new Thread[numThreads];
                for (int i = 0; i < numThreads; i++)
                {
                    tasks[i] = new Thread(Disconnect);
                    tasks[i].Start();
                }

                for (int i = 0; i < numThreads; i++)
                {
                    tasks[i].Join();
                }

                caughtException = _error as AggregateException;
                if (caughtException != null)
                {
                    break;
                }
            }

            // Assert
            // This test does not always work on the build server, requires more than 2 CPU(s) for better reliability
            if (caughtException != null)
            {
                Assert.IsTrue(errorEvent.WaitOne(TimeSpan.FromSeconds(5)));
                Assert.IsNotNull(pusherException, nameof(PusherException));
                Assert.AreEqual(pusherException.Message, caughtException.InnerException.Message);
                Assert.AreEqual(ErrorCodes.ClientTimeout, pusherException.PusherCode);
            }
        }
Exemple #6
0
        /// <summary>
        /// incoming error
        /// входящая ошибка
        /// </summary>
        private void _pusher_Error(object sender, PusherException error)
        {
            SendLogMessage(error.ToString(), LogMessageType.Error);

            if (NeadReconnectEvent != null)
            {
                NeadReconnectEvent();
            }
        }
Exemple #7
0
 public async void Create(PusherException e)
 {
     var response = new HttpClientResponse();
     await response.Convert(HttpClientRequestService.Create("app-errors", new {
         error_id   = GetErrorId(e),
         message    = e.Message ?? DEFAULT_MESSAGE + " [PUSHER ERROR]",
         stacktrace = e.StackTrace ?? DEFAULT_STACKTRACE + " [PUSHER ERROR]"
     }));
 }
Exemple #8
0
 private void _pusher_Error(object sender, PusherException error)
 {
     try
     {
         _pusher.Disconnect();
         Thread.Sleep(1000);
         _pusher.Connect();
     }
     catch
     { }
 }
 private static void ErrorOccurred(object sender, PusherException error)
 {
     if (error is EventEmitterActionException <PusherEvent> )
     {
         DependencyService.Get <Toast>().Show("(#11) Error in event " + ((EventEmitterActionException <PusherEvent>)error).EventName + " (WebSocketService)");
     }
     else
     {
         DependencyService.Get <Toast>().Show("(#11) Er was een probleem met de pusher (WebSocketService)");
     }
     UnitOfWork.Instance.ErrorRepository.Create(error);
 }
        public async Task PusherShouldErrorWhenSubscribeTimesOutAsync()
        {
            // Arrange
            AutoResetEvent  errorEvent      = new AutoResetEvent(false);
            PusherException exception       = null;
            PusherException caughtException = null;

            ChannelTypes channelType = ChannelTypes.Presence;
            string       channelName = ChannelNameFactory.CreateUniqueChannelName(channelType: channelType);
            var          pusher      = PusherFactory.GetPusher(channelType: channelType, saveTo: _clients);
            await pusher.ConnectAsync().ConfigureAwait(false);

            ((IPusher)pusher).PusherOptions.ClientTimeout = TimeSpan.FromMilliseconds(20);

            pusher.Error += (sender, error) =>
            {
                exception = error;
                errorEvent.Set();
            };

            // Act

            // Try to generate the error multiple times as it does not always error the first time
            for (int attempt = 0; attempt < TimeoutRetryAttempts; attempt++)
            {
                try
                {
                    await pusher.SubscribePresenceAsync <FakeUserInfo>(channelName).ConfigureAwait(false);
                }
                catch (Exception error)
                {
                    caughtException = error as PusherException;
                }

                if (caughtException != null)
                {
                    break;
                }
            }

            // Assert
            // This test does not always work on the build server, requires more than 2 CPU(s) for better reliability
            if (caughtException != null)
            {
                Assert.IsTrue(errorEvent.WaitOne(TimeSpan.FromSeconds(5)));
                Assert.IsNotNull(exception, $"Error expected to be {nameof(PusherException)}");
                Assert.AreEqual(exception.Message, caughtException.Message);
                Assert.AreEqual(ErrorCodes.ClientTimeout, exception.PusherCode, "Unexpected error: " + exception.Message);
            }
        }
        public void PusherShouldErrorWhenConnectTimesOut()
        {
            // Arrange
            AutoResetEvent     errorEvent      = new AutoResetEvent(false);
            PusherException    exception       = null;
            AggregateException caughtException = null;

            var pusher = PusherFactory.GetPusher(saveTo: _clients, timeoutPeriodMilliseconds: 10);

            pusher.Error += (sender, error) =>
            {
                exception = error;
                errorEvent.Set();
            };

            // Act - trying to connect multiple times gives us increased code coverage on connection timeouts.
            List <Task> tasks = new List <Task>();

            for (int i = 0; i < 2; i++)
            {
                tasks.Add(Task.Run(() =>
                {
                    return(pusher.ConnectAsync());
                }));
            }

            try
            {
                Task.WaitAll(tasks.ToArray());
            }
            catch (AggregateException error)
            {
                caughtException = error;
            }

            // Assert
            Assert.IsNotNull(caughtException, nameof(AggregateException));
            Assert.IsTrue(errorEvent.WaitOne(TimeSpan.FromSeconds(5)));
            Assert.IsNotNull(exception, nameof(PusherException));
            Assert.AreEqual(exception.Message, caughtException.InnerException.Message);
            Assert.AreEqual(ErrorCodes.ClientTimeout, exception.PusherCode);
        }
        public async Task PrivateChannelConnectThenSubscribeWithoutAuthorizerAsync()
        {
            // Arrange
            var             pusher          = PusherFactory.GetPusher(saveTo: _clients);
            PusherException caughtException = null;

            // Act
            try
            {
                await ConnectThenSubscribeTestAsync(ChannelTypes.Private, pusher : pusher).ConfigureAwait(false);
            }
            catch (PusherException ex)
            {
                caughtException = ex;
            }

            // Assert
            Assert.IsNotNull(caughtException);
            StringAssert.Contains("An Authorizer needs to be provided when subscribing to the private or presence channel", caughtException.Message);
        }
Exemple #13
0
 private void _pusherClient_Error(object sender, PusherException error)
 {
     log.Write(LogLevel.Error, error.ToString());
     PusherError?.Invoke(error);
 }
Exemple #14
0
 private static void _pusher_Error(object sender, PusherException error)
 {
     Console.WriteLine(JsonConvert.SerializeObject(error));
 }
Exemple #15
0
 private void OnPusherOnError(object s, PusherException e)
 {
     Debug.Log("Errored");
 }
Exemple #16
0
 private void _pusher_Error(object sender, PusherException error)
 {
     Debug.WriteLine($"Error in Pusher: {error.ToString()}");
     _loggingService.WriteError(error);
 }
 private static void pusher_Error(object sender, PusherException error)
 {
     Console.WriteLine(error.Message);
 }
Exemple #18
0
        private static void HandlePusherError(object sender, PusherException error)
        {
            Pusher pusher = sender as Pusher;

            System.Diagnostics.Trace.TraceError($"Pusher error detected on socket {pusher.SocketID}:{Environment.NewLine}{error}");
        }
 private void PusherError(object sender, PusherException error)
 {
     Debug.WriteLine("Pusher Channels Error: " + error.ToString());
     connectionStatusBorder.Background = new SolidColorBrush(Windows.UI.Colors.DarkRed);
     connectionStatusText.Text         = "Error: " + error.ToString();
 }
Exemple #20
0
 private void OnPusherOnError(object s, PusherException e)
 {
     //MessageBox.Show("Errored");
 }
Exemple #21
0
 static void PusherError(object sender, PusherException error)
 {
     TraceMessage(sender, $"{Environment.NewLine}Pusher Error: {error.Message}{Environment.NewLine}{error}");
 }
Exemple #22
0
 static void Error(object sender, PusherException ex)
 {
     Console.WriteLine(ex.ToString());
 }
Exemple #23
0
 private void PusherError(object sender, PusherException error)
 {
     // todo handle
     ((Subject <Channel>)UserChannel).OnNext(null);
     _logger.Error(error, "Pusher error: {0}", error.Message);
 }
        public async Task PusherShouldErrorWhenGivenAnInvalidAppKeyAsync()
        {
            // Arrange
            PusherException        exception          = null;
            PusherException        caughtException    = null;
            bool                   connected          = false;
            bool                   disconnected       = false;
            bool                   errored            = false;
            int                    expectedFinalCount = 1;
            List <ConnectionState> stateChangeLog     = new List <ConnectionState>(expectedFinalCount);
            object                 sync   = new object();
            var                    pusher = new Pusher("Invalid");

            pusher.Connected += sender =>
            {
                connected = true;
            };

            pusher.ConnectionStateChanged += (sender, state) =>
            {
                lock (sync)
                {
                    stateChangeLog.Add(state);
                }
            };

            pusher.Disconnected += sender =>
            {
                disconnected = true;
            };

            pusher.Error += (sender, error) =>
            {
                errored   = true;
                exception = error;
            };

            // Act
            try
            {
                await pusher.ConnectAsync().ConfigureAwait(false);
            }
            catch (PusherException error)
            {
                caughtException = error;
            }

            /*
             *  Wait for 1.5 seconds to ensure that auto reconnect does not happen.
             *  The value of disconnected would be true if auto reconnect occured and
             *  there would be more than a single state change.
             */
            await Task.Delay(1500).ConfigureAwait(false);

            // Assert
            Assert.AreEqual(ConnectionState.Connecting, pusher.State, nameof(pusher.State));
            Assert.IsFalse(connected, nameof(connected));
            Assert.IsFalse(disconnected, nameof(disconnected));
            Assert.IsTrue(errored, nameof(errored));
            Assert.IsNotNull(exception);
            Assert.IsNotNull(caughtException);
            Assert.AreEqual(exception.Message, caughtException.Message);
            Assert.AreEqual(ErrorCodes.ApplicationDoesNotExist, exception.PusherCode);
            Assert.AreEqual(expectedFinalCount, stateChangeLog.Count, nameof(expectedFinalCount));
            Assert.AreEqual(ConnectionState.Connecting, stateChangeLog[0]);
        }
Exemple #25
0
 private static void _pusher_Error(object sender, PusherException error)
 {
     System.Console.WriteLine("Pusher Error: " + error);
 }
        private void PusherClientError(object sender, PusherException error)
        {
            var message = $"PusherClient Error: {error.ToString()}";

            Error(message);
        }
Exemple #27
0
 private void OnError(object sender, PusherException eventArgs)
 {
     System.Diagnostics.Debug.Print(eventArgs.Message);
 }
Exemple #28
0
 private void OnPusherOnError(object s, PusherException e)
 {
     // Todo handle an error
 }
 static void _pusher_Error(object sender, PusherException error)
 {
     Console.WriteLine("Pusher Error: " + error.ToString());
 }
Exemple #30
0
 private void PusherError(object sender, PusherException pusherException)
 {
     _logger.LogError(pusherException, "An Pusher exception occured");
 }