Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions websocket-sharp/ErrorEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,29 @@ namespace WebSocketSharp
/// </summary>
/// <remarks>
/// A <see cref="WebSocket.OnError"/> event occurs when the <see cref="WebSocket"/> gets an error.
/// If you want to get the error message, you access the <see cref="ErrorEventArgs.Message"/> property.
/// If you would like to get the error message, you should access the <see cref="Message"/>
/// property.
/// </remarks>
public class ErrorEventArgs : EventArgs
{
#region Private Fields

private string _message;
private Exception _exception;

#endregion

#region Internal Constructors

internal ErrorEventArgs (string message)
: this (message, null)
{
}

internal ErrorEventArgs (string message, Exception exception)
{
Message = message;
_message = message;
_exception = exception;
}

#endregion
Expand All @@ -54,9 +68,25 @@ internal ErrorEventArgs (string message)
/// Gets the error message.
/// </summary>
/// <value>
/// A <see cref="string"/> that contains an error message.
/// A <see cref="string"/> that represents the error message.
/// </value>
public string Message { get; private set; }
public string Message {
get {
return _message;
}
}

/// <summary>
/// Gets the exception that caused the error.
/// </summary>
/// A <see cref="Exception"/> instance that represents the cause of the error,
/// or <see langword="null"/> if the error isn't due to an exception.
/// </value>
public Exception Exception {
get {
return _exception;
}
}

#endregion
}
Expand Down
18 changes: 9 additions & 9 deletions websocket-sharp/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ private void acceptException (Exception exception, string reason)
msg = null;
}

error (msg ?? code.GetMessage ());
error (msg ?? code.GetMessage (), exception);
close (code, reason ?? code.GetMessage (), false);
}

Expand Down Expand Up @@ -724,7 +724,7 @@ private void close (PayloadData payload, bool send, bool wait)
}
catch (Exception ex) {
_logger.Fatal (ex.ToString ());
error ("An exception has occurred while OnClose.");
error ("An exception has occurred while OnClose.", ex);
}
}

Expand Down Expand Up @@ -940,9 +940,9 @@ private bool doHandshake ()
return true;
}

private void error (string message)
private void error (string message, Exception exc = null)
{
OnError.Emit (this, new ErrorEventArgs (message));
OnError.Emit (this, new ErrorEventArgs (message, exc));
}

private void init ()
Expand Down Expand Up @@ -1089,7 +1089,7 @@ private bool send (Opcode opcode, byte [] data)
}
catch (Exception ex) {
_logger.Fatal (ex.ToString ());
error ("An exception has occurred while sending a data.");
error ("An exception has occurred while sending a data.", ex);
}

return sent;
Expand All @@ -1113,7 +1113,7 @@ private bool send (Opcode opcode, Stream stream)
}
catch (Exception ex) {
_logger.Fatal (ex.ToString ());
error ("An exception has occurred while sending a data.");
error ("An exception has occurred while sending a data.", ex);
}
finally {
if (compressed)
Expand Down Expand Up @@ -1366,7 +1366,7 @@ internal void Send (
}
catch (Exception ex) {
_logger.Fatal (ex.ToString ());
error ("An exception has occurred while sending a data.");
error ("An exception has occurred while sending a data.", ex);
}
}
}
Expand All @@ -1390,7 +1390,7 @@ internal void Send (
}
catch (Exception ex) {
_logger.Fatal (ex.ToString ());
error ("An exception has occurred while sending a data.");
error ("An exception has occurred while sending a data.", ex);
}
}
}
Expand Down Expand Up @@ -1935,7 +1935,7 @@ public void SendAsync (Stream stream, int length, Action<bool> completed)
},
ex => {
_logger.Fatal (ex.ToString ());
error ("An exception has occurred while sending a data.");
error ("An exception has occurred while sending a data.", ex);
});
}

Expand Down