Skip to content

Commit

Permalink
fix: handling connection failure status with additional information t…
Browse files Browse the repository at this point in the history
…o user
  • Loading branch information
mohitpubnub committed Jun 13, 2024
1 parent 47c136b commit d56cfc4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,6 +26,7 @@ public EmitStatusInvocation(PNStatus status)
if (status != null)
{
this.StatusCategory = status.Category;
this.StatusCode = status.StatusCode;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 10 additions & 2 deletions src/Api/PubnubApi/Model/Consumer/PNStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ public class PNStatus

public PNStatus() { }

public PNStatus(Exception e, PNOperationType operationType, PNStatusCategory category, IEnumerable<string> affectedChannels = null, IEnumerable<string> affectedChannelGroups = null)
public PNStatus(Exception e, PNOperationType operationType, PNStatusCategory category, IEnumerable<string> affectedChannels = null, IEnumerable<string> affectedChannelGroups = null, int? statusCode = null)
{
this.Error = e != null;
this.Operation = operationType;
this.ErrorData = new PNErrorData(e?.Message, e);
this.AffectedChannels = affectedChannels?.ToList();
this.AffectedChannelGroups = affectedChannelGroups?.ToList();
this.Category = category;
this.StatusCode = statusCode ?? 200;
if (!Error)
{
this.StatusCode = 200;
Expand All @@ -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; }
Expand Down

0 comments on commit d56cfc4

Please sign in to comment.