Preserve stack trace for websocket errors

This commit is contained in:
Brandon Smith
2015-09-04 19:21:03 -03:00
parent ce2a4dfa2b
commit 5b432769fb
3 changed files with 5 additions and 4 deletions

View File

@@ -42,7 +42,7 @@ namespace Discord
}
catch (OperationCanceledException)
{
throw _disconnectReason;// ?? new Exception("Operation was cancelled");
_disconnectReason.Throw();
}
try { _connectWaitOnLogin2.Wait(cancelToken); } //Waiting on READY handler
catch (OperationCanceledException) { return; }

View File

@@ -109,7 +109,7 @@ namespace Discord
}
catch (OperationCanceledException)
{
throw _disconnectReason;
_disconnectReason.Throw();
}
SetConnected();

View File

@@ -3,6 +3,7 @@ using System;
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Net.WebSockets;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -23,7 +24,7 @@ namespace Discord
protected CancellationTokenSource _disconnectToken;
protected string _host;
protected int _timeout, _heartbeatInterval;
protected Exception _disconnectReason;
protected ExceptionDispatchInfo _disconnectReason;
private ClientWebSocket _webSocket;
private DateTime _lastHeartbeat;
private Task _task;
@@ -103,7 +104,7 @@ namespace Discord
if (_disconnectReason == null)
{
_wasDisconnectUnexpected = isUnexpected;
_disconnectReason = ex;
_disconnectReason = ExceptionDispatchInfo.Capture(ex);
_disconnectToken.Cancel();
}
}