Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #397. Call callback instead of throwing AblyException #398

Merged
merged 4 commits into from Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/IO.Ably.Shared/Realtime/Presence.cs
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using IO.Ably.Transport;
using IO.Ably.Types;
using IO.Ably.Utils;
using Newtonsoft.Json.Linq;

namespace IO.Ably.Realtime
Expand Down Expand Up @@ -469,11 +470,13 @@ internal void UpdatePresence(PresenceMessage msg, Action<bool, ErrorInfo> callba
case ConnectionState.Connected:
break;
default:
throw new AblyException(
new ErrorInfo(
$"Unable to enter presence channel when connection is in a ${_connection.Connection.State} state",
91001,
HttpStatusCode.BadRequest));
var error = new ErrorInfo(
$"Unable to enter presence channel when connection is in a ${_connection.Connection.State} state.",
91001,
HttpStatusCode.BadRequest);
Logger.Warning(error.ToString());
ActionUtils.SafeExecute(() => callback?.Invoke(false, error), Logger, nameof(UpdatePresence));
return;
}

switch (_channel.State)
Expand All @@ -495,7 +498,10 @@ internal void UpdatePresence(PresenceMessage msg, Action<bool, ErrorInfo> callba
_connection.Send(message, callback);
break;
default:
throw new AblyException($"Unable to enter presence channel in {_channel.State} state", 91001, HttpStatusCode.BadRequest);
var error = new ErrorInfo($"Unable to enter presence channel in {_channel.State} state", 91001);
Logger.Warning(error.ToString());
ActionUtils.SafeExecute(() => callback?.Invoke(false, error), Logger, nameof(UpdatePresence));
return;
}
}

Expand Down
18 changes: 6 additions & 12 deletions src/IO.Ably.Tests.Shared/Realtime/PresenceSandboxSpecs.cs
Expand Up @@ -1720,14 +1720,11 @@ async Task TestWithConnectionState(ConnectionState state, RealtimeCommand change
await client.WaitForState(state);

var didError = false;
try
{
channel.Presence.Enter(client.Connection.State.ToString());
}
catch (AblyException e)
var result = await channel.Presence.EnterAsync(client.Connection.State.ToString());
if (result.IsFailure)
{
didError = true;
e.ErrorInfo.Code.Should().Be(91001);
result.Error.Code.Should().Be(91001);
errCount++;
}

Expand Down Expand Up @@ -1780,14 +1777,11 @@ async Task TestWithChannelState(ChannelState state)
await channel.WaitForState(state);

var didError = false;
try
{
channel.Presence.Enter(client.Connection.State.ToString());
}
catch (AblyException e)
var result = await channel.Presence.EnterAsync(client.Connection.State.ToString());
if (result.IsFailure)
{
didError = true;
e.ErrorInfo.Code.Should().Be(91001);
result.Error.Code.Should().Be(91001);
errCount++;
}

Expand Down
6 changes: 5 additions & 1 deletion src/IO.Ably.Tests.Shared/Realtime/RealtimeWorkflowSpecs.cs
Expand Up @@ -98,7 +98,11 @@ public class ConnectingCommandSpecs : AblyRealtimeSpecs
public async Task WithInboundErrorMessageWhenItCanUseFallBack_ShouldClearsConnectionKey()
{
// Arrange
var client = GetRealtimeClient();
var client = GetRealtimeClient(options =>
{
options.RealtimeRequestTimeout = TimeSpan.FromSeconds(60);
options.DisconnectedRetryTimeout = TimeSpan.FromSeconds(60);
});

await client.WaitForState(ConnectionState.Connecting);

Expand Down