diff --git a/src/Api/PubnubApi/EventEngine/Subscribe/Effects/HandshakeEffectHandler.cs b/src/Api/PubnubApi/EventEngine/Subscribe/Effects/HandshakeEffectHandler.cs index edc736288..bf3aa197a 100644 --- a/src/Api/PubnubApi/EventEngine/Subscribe/Effects/HandshakeEffectHandler.cs +++ b/src/Api/PubnubApi/EventEngine/Subscribe/Effects/HandshakeEffectHandler.cs @@ -124,11 +124,11 @@ public override async Task Run(HandshakeReconnectInvocation invocation) { if (retryConfiguration == null) { - eventQueue.Enqueue(new HandshakeReconnectGiveUpEvent() { Status = new PNStatus(new Exception(""), PNOperationType.PNSubscribeOperation, PNStatusCategory.PNConnectionErrorCategory, invocation.Channels, invocation.ChannelGroups ) }); + eventQueue.Enqueue(new HandshakeReconnectGiveUpEvent() { Status = new PNStatus(new Exception(""), PNOperationType.PNSubscribeOperation, PNStatusCategory.PNConnectionErrorCategory, invocation.Channels, invocation.ChannelGroups, invocation.Reason.StatusCode ) }); } else if (!retryConfiguration.RetryPolicy.ShouldRetry(invocation.AttemptedRetries, invocation.Reason)) { - eventQueue.Enqueue(new HandshakeReconnectGiveUpEvent() { Status = new PNStatus(new Exception(""), PNOperationType.PNSubscribeOperation, PNStatusCategory.PNConnectionErrorCategory, invocation.Channels, invocation.ChannelGroups ) }); + eventQueue.Enqueue(new HandshakeReconnectGiveUpEvent() { Status = new PNStatus(new Exception(""), PNOperationType.PNSubscribeOperation, PNStatusCategory.PNConnectionErrorCategory, invocation.Channels, invocation.ChannelGroups, invocation.Reason.StatusCode ) }); } else { diff --git a/src/Api/PubnubApi/EventEngine/Subscribe/Effects/ReceivingEffectHandler.cs b/src/Api/PubnubApi/EventEngine/Subscribe/Effects/ReceivingEffectHandler.cs index f632ad53a..d9a5526cf 100644 --- a/src/Api/PubnubApi/EventEngine/Subscribe/Effects/ReceivingEffectHandler.cs +++ b/src/Api/PubnubApi/EventEngine/Subscribe/Effects/ReceivingEffectHandler.cs @@ -98,11 +98,11 @@ public override async Task Run(ReceiveReconnectInvocation invocation) var retryConfiguration = pubnubConfiguration.RetryConfiguration; if (retryConfiguration == null) { - eventQueue.Enqueue(new ReceiveReconnectGiveUpEvent() { Status = new PNStatus(new Exception(""), PNOperationType.PNSubscribeOperation, PNStatusCategory.PNUnexpectedDisconnectCategory, invocation.Channels, invocation.ChannelGroups ) }); + eventQueue.Enqueue(new ReceiveReconnectGiveUpEvent() { Status = new PNStatus(new Exception(""), PNOperationType.PNSubscribeOperation, PNStatusCategory.PNUnexpectedDisconnectCategory, invocation.Channels, invocation.ChannelGroups, invocation.Reason.StatusCode ) }); } else if (!retryConfiguration.RetryPolicy.ShouldRetry(invocation.AttemptedRetries, invocation.Reason)) { - eventQueue.Enqueue(new ReceiveReconnectGiveUpEvent() { Status = new PNStatus(new Exception(""), PNOperationType.PNSubscribeOperation, PNStatusCategory.PNUnexpectedDisconnectCategory, invocation.Channels, invocation.ChannelGroups ) }); + eventQueue.Enqueue(new ReceiveReconnectGiveUpEvent() { Status = new PNStatus(new Exception(""), PNOperationType.PNSubscribeOperation, PNStatusCategory.PNUnexpectedDisconnectCategory, invocation.Channels, invocation.ChannelGroups, invocation.Reason.StatusCode ) }); } else { diff --git a/src/Api/PubnubApi/EventEngine/Subscribe/Invocations/SubscriptionInvocations.cs b/src/Api/PubnubApi/EventEngine/Subscribe/Invocations/SubscriptionInvocations.cs index 22a8cb808..582e33331 100644 --- a/src/Api/PubnubApi/EventEngine/Subscribe/Invocations/SubscriptionInvocations.cs +++ b/src/Api/PubnubApi/EventEngine/Subscribe/Invocations/SubscriptionInvocations.cs @@ -17,6 +17,7 @@ public class EmitStatusInvocation : Core.IEffectInvocation { // TODO merge status variables into one? public PNStatusCategory StatusCategory; public PNStatus Status; + public int StatusCode; public string Name { get; set; } = "EMIT_STATUS"; public EmitStatusInvocation(PNStatus status) @@ -25,6 +26,7 @@ public EmitStatusInvocation(PNStatus status) if (status != null) { this.StatusCategory = status.Category; + this.StatusCode = status.StatusCode; } } diff --git a/src/Api/PubnubApi/EventEngine/Subscribe/States/HandshakeReconnectingState.cs b/src/Api/PubnubApi/EventEngine/Subscribe/States/HandshakeReconnectingState.cs index 68a5ebf6b..ea803c84b 100644 --- a/src/Api/PubnubApi/EventEngine/Subscribe/States/HandshakeReconnectingState.cs +++ b/src/Api/PubnubApi/EventEngine/Subscribe/States/HandshakeReconnectingState.cs @@ -40,7 +40,7 @@ public override TransitionResult Transition(IEvent e) Channels = this.Channels, ChannelGroups = this.ChannelGroups, }.With( - new EmitStatusInvocation(handshakeReconnectGiveUp.Status) + new EmitStatusInvocation(new PNStatus(handshakeReconnectGiveUp.Status) ) ), Events.HandshakeReconnectFailureEvent handshakeReconnectFailure => new HandshakeReconnectingState() { diff --git a/src/Api/PubnubApi/Model/Consumer/PNStatus.cs b/src/Api/PubnubApi/Model/Consumer/PNStatus.cs index 2c0d34eb3..361ece757 100644 --- a/src/Api/PubnubApi/Model/Consumer/PNStatus.cs +++ b/src/Api/PubnubApi/Model/Consumer/PNStatus.cs @@ -14,7 +14,7 @@ public class PNStatus public PNStatus() { } - public PNStatus(Exception e, PNOperationType operationType, PNStatusCategory category, IEnumerable affectedChannels = null, IEnumerable affectedChannelGroups = null) + public PNStatus(Exception e, PNOperationType operationType, PNStatusCategory category, IEnumerable affectedChannels = null, IEnumerable affectedChannelGroups = null, int? statusCode = null) { this.Error = e != null; this.Operation = operationType; @@ -22,6 +22,7 @@ public PNStatus(Exception e, PNOperationType operationType, PNStatusCategory cat this.AffectedChannels = affectedChannels?.ToList(); this.AffectedChannelGroups = affectedChannelGroups?.ToList(); this.Category = category; + this.StatusCode = statusCode ?? 200; if (!Error) { this.StatusCode = 200; @@ -31,10 +32,17 @@ public PNStatus(Exception e, PNOperationType operationType, PNStatusCategory cat internal PNStatus(object endpointOperation) { this.savedEndpointOperation = endpointOperation; + if(endpointOperation is PNStatus) { + var status = (PNStatus)endpointOperation; + this.Error = status.Error; + this.Category = status.Category; + this.StatusCode = status.StatusCode; + this.ErrorData = status.ErrorData; + } } [JsonConverter(typeof(StringEnumConverter))] - public PNStatusCategory Category { get; internal set; } + public PNStatusCategory Category { get; set; } public PNErrorData ErrorData { get; internal set; } public bool Error { get; internal set; }