Exemple #1
0
 internal static void ResponseCallbackWebExceptionHandler <T> (CustomEventArgs <T> cea, RequestState <T> requestState,
                                                               WebException webEx,
                                                               PubnubErrorFilter.Level errorLevel)
 {
     if ((requestState != null) && (requestState.ChannelEntities != null || requestState.RespType != ResponseType.Time))
     {
         if (requestState.RespType.Equals(ResponseType.SubscribeV2) ||
             requestState.RespType.Equals(ResponseType.PresenceV2)
             )
         {
             if (webEx.Message.IndexOf("The request was aborted: The request was canceled") == -1 ||
                 webEx.Message.IndexOf("Machine suspend mode enabled. No request will be processed.") == -1)
             {
                 PubnubCallbacks.FireErrorCallbacksForAllChannels <T> (webEx, requestState,
                                                                       PubnubErrorSeverity.Warn, errorLevel);
             }
         }
         else
         {
             PubnubCallbacks.FireErrorCallbacksForAllChannels <T> (webEx, requestState,
                                                                   PubnubErrorSeverity.Warn, errorLevel);
         }
     }
     ProcessResponseCallbackWebExceptionHandler <T> (webEx, requestState, errorLevel);
 }
Exemple #2
0
        internal static void CommonExceptionHandler <T> (RequestState <T> requestState, string message, bool requestTimeout,
                                                         PubnubErrorFilter.Level errorLevel
                                                         )
        {
            if (requestTimeout)
            {
                message = "Operation Timeout";
                #if (ENABLE_PUBNUB_LOGGING)
                LoggingMethod.WriteToLog(string.Format("DateTime {0}, {1} CommonExceptionHandler response={2}", DateTime.Now.ToString(),
                                                       requestState.RespType.ToString(), message), LoggingMethod.LevelInfo);
                #endif

                PubnubCallbacks.FireErrorCallbacksForAllChannels <T> (message, requestState,
                                                                      PubnubErrorSeverity.Critical, Helpers.GetTimeOutErrorCode(requestState.RespType), errorLevel);
            }
            else
            {
                #if (ENABLE_PUBNUB_LOGGING)
                LoggingMethod.WriteToLog(string.Format("DateTime {0}, {1} CommonExceptionHandler response={2}", DateTime.Now.ToString(), requestState.RespType.ToString(), message), LoggingMethod.LevelInfo);
                #endif

                PubnubCallbacks.FireErrorCallbacksForAllChannels <T> (message, requestState,
                                                                      PubnubErrorSeverity.Critical, PubnubErrorCode.None, errorLevel);
            }
        }
Exemple #3
0
 internal static void ResponseCallbackWebExceptionHandler <T> (CustomEventArgs <T> cea, RequestState <T> requestState,
                                                               WebException webEx, string channel, SafeDictionary <PubnubChannelCallbackKey, object> channelCallbacks,
                                                               PubnubErrorFilter.Level errorLevel)
 {
     if (requestState.Channels != null || requestState.RespType == ResponseType.Time)
     {
         if (requestState.RespType == ResponseType.Subscribe ||
             requestState.RespType == ResponseType.Presence)
         {
             if (webEx.Message.IndexOf("The request was aborted: The request was canceled") == -1 ||
                 webEx.Message.IndexOf("Machine suspend mode enabled. No request will be processed.") == -1)
             {
                 PubnubCallbacks.FireErrorCallbacksForAllChannels <T> (webEx, requestState,
                                                                       PubnubErrorSeverity.Warn, channelCallbacks,
                                                                       true, errorLevel);
             }
         }
         else
         {
             PubnubCallbacks.CallErrorCallback <T> (webEx, requestState, channel,
                                                    PubnubErrorSeverity.Warn, requestState.ErrorCallback, errorLevel);
         }
     }
     ProcessResponseCallbackWebExceptionHandler <T> (webEx, requestState, channel, errorLevel);
 }
Exemple #4
0
        internal static void CheckSubscribedChannelsAndSendCallbacks <T> (string[] channels, bool isPresence,
                                                                          ResponseType type, int pubnubNetworkCheckRetries, SafeDictionary <PubnubChannelCallbackKey,
                                                                                                                                            object> channelCallbacks, PubnubErrorFilter.Level errorLevel)
        {
            if (channels != null && channels.Length > 0)
            {
                string          message     = string.Format("Unsubscribed after {0} failed retries", pubnubNetworkCheckRetries);;
                PubnubErrorCode pnErrorCode = PubnubErrorCode.UnsubscribedAfterMaxRetries;

                if (isPresence)
                {
                    message     = string.Format("Presence Unsubscribed after {0} failed retries", pubnubNetworkCheckRetries);
                    pnErrorCode = PubnubErrorCode.PresenceUnsubscribedAfterMaxRetries;
                }

                PubnubCallbacks.FireErrorCallbacksForAllChannels <T> (message, null, channels,
                                                                      PubnubErrorSeverity.Critical, channelCallbacks,
                                                                      false, pnErrorCode, type, errorLevel);

                #if (ENABLE_PUBNUB_LOGGING)
                LoggingMethod.WriteToLog(string.Format("DateTime {0}, {1} Subscribe JSON network error response={2}",
                                                       DateTime.Now.ToString(), (isPresence)?"Presence":"", message), LoggingMethod.LevelInfo);
                #endif
            }
        }
Exemple #5
0
        internal static void ResponseCallbackErrorOrTimeoutHandler <T> (CustomEventArgs <T> cea, RequestState <T> requestState,
                                                                        PubnubErrorFilter.Level errorLevel)
        {
            WebException webEx = new WebException(cea.Message);

            if ((cea.Message.Contains("NameResolutionFailure") ||
                 cea.Message.Contains("ConnectFailure") ||
                 cea.Message.Contains("ServerProtocolViolation") ||
                 cea.Message.Contains("ProtocolError")
                 ))
            {
                webEx = new WebException("Network connnect error", WebExceptionStatus.ConnectFailure);

                PubnubCallbacks.FireErrorCallbacksForAllChannels <T> (cea.Message, requestState,
                                                                      PubnubErrorSeverity.Warn, PubnubErrorCode.NoInternetRetryConnect, errorLevel);
            }
            else if (cea.IsTimeout || Utility.CheckRequestTimeoutMessageInError(cea))
            {
            }
            else if ((cea.Message.Contains("403")) ||
                     (cea.Message.Contains("java.io.FileNotFoundException")) ||
                     ((PubnubUnity.Version.Contains("UnityWeb")) && (cea.Message.Contains("Failed downloading"))))
            {
                CreateErrorCodeAndCallErrorCallback <T> (403, cea, requestState, errorLevel);
            }
            else if (cea.Message.Contains("500"))
            {
                CreateErrorCodeAndCallErrorCallback <T> (500, cea, requestState, errorLevel);
            }
            else if (cea.Message.Contains("502"))
            {
                CreateErrorCodeAndCallErrorCallback <T> (502, cea, requestState, errorLevel);
            }
            else if (cea.Message.Contains("503"))
            {
                CreateErrorCodeAndCallErrorCallback <T> (503, cea, requestState, errorLevel);
            }
            else if (cea.Message.Contains("504"))
            {
                CreateErrorCodeAndCallErrorCallback <T> (504, cea, requestState, errorLevel);
            }
            else if (cea.Message.Contains("414"))
            {
                CreateErrorCodeAndCallErrorCallback <T> (414, cea, requestState, errorLevel);
            }
            else if (cea.Message.Contains("451"))
            {
                CreateErrorCodeAndCallErrorCallback <T> (451, cea, requestState, errorLevel);
            }
            else if (cea.Message.Contains("481"))
            {
                CreateErrorCodeAndCallErrorCallback <T> (481, cea, requestState, errorLevel);
            }
            else
            {
                CreateErrorCodeAndCallErrorCallback <T> (400, cea, requestState, errorLevel);
            }
            ProcessResponseCallbackWebExceptionHandler <T> (webEx, requestState, errorLevel);
        }
Exemple #6
0
 internal static void PushNotificationExceptionHandler <T>(RequestState <T> requestState, bool requestTimeout,
                                                           PubnubErrorFilter.Level errorLevel)
 {
     if (requestTimeout)
     {
         string message = (requestTimeout) ? "Operation Timeout" : "Network connnect error";
         #if (ENABLE_PUBNUB_LOGGING)
         LoggingMethod.WriteToLog(string.Format("DateTime {0}, PushExceptionHandler response={1}", DateTime.Now.ToString(), message), LoggingMethod.LevelInfo);
         #endif
         PubnubCallbacks.FireErrorCallbacksForAllChannels <T> (message, requestState,
                                                               PubnubErrorSeverity.Critical, PubnubErrorCode.PushNotificationTimeout, errorLevel);
     }
 }
Exemple #7
0
 internal static void ProcessWrapResultBasedOnResponseTypeException <T> (ResponseType type, string[] channels,
                                                                         Action <PubnubClientError> errorCallback, SafeDictionary <PubnubChannelCallbackKey, object> channelCallbacks,
                                                                         PubnubErrorFilter.Level errorLevel, Exception ex)
 {
     if (channels != null)
     {
         if (type == ResponseType.Subscribe || type == ResponseType.Presence)
         {
             PubnubCallbacks.FireErrorCallbacksForAllChannels <T> (ex, channels, PubnubErrorSeverity.Critical,
                                                                   channelCallbacks, false, PubnubErrorCode.None, type, errorLevel);
         }
         else
         {
             if (errorCallback != null)
             {
                 PubnubCallbacks.CallErrorCallback <T> (ex, null, string.Join(",", channels), PubnubErrorCode.None,
                                                        PubnubErrorSeverity.Critical, errorCallback, errorLevel);
             }
         }
     }
 }
Exemple #8
0
 internal static void ResponseCallbackExceptionHandler <T> (CustomEventArgs <T> cea, RequestState <T> requestState,
                                                            Exception ex, PubnubErrorFilter.Level errorLevel)
 {
     #if (ENABLE_PUBNUB_LOGGING)
     LoggingMethod.WriteToLog(string.Format("DateTime {0}, Process Response Exception: = {1}", DateTime.Now.ToString(), ex.ToString()), LoggingMethod.LevelError);
     #endif
     if (requestState.ChannelEntities != null)
     {
         if (requestState.RespType.Equals(ResponseType.SubscribeV2) ||
             requestState.RespType.Equals(ResponseType.PresenceV2)
             )
         {
             PubnubCallbacks.FireErrorCallbacksForAllChannels(ex, requestState,
                                                              PubnubErrorSeverity.Warn, PubnubErrorCode.None, errorLevel);
         }
         else
         {
             PubnubCallbacks.FireErrorCallbacksForAllChannels <T> (ex, requestState,
                                                                   PubnubErrorSeverity.Critical, PubnubErrorCode.None, errorLevel);
         }
     }
     ProcessResponseCallbackExceptionHandler <T> (ex, requestState, errorLevel);
 }