Skip to content
Open
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
10 changes: 7 additions & 3 deletions src/Fleck/WebSocketException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ namespace Fleck
{
public class WebSocketException : Exception
{
public WebSocketException(ushort statusCode) : base()
public WebSocketException(ushort statusCode) : this(statusCode, PrepareExceptionMessage(statusCode))
{
StatusCode = statusCode;
}

public WebSocketException(ushort statusCode, string message) : base(message)
{
StatusCode = statusCode;
Expand All @@ -19,5 +18,10 @@ public WebSocketException(ushort statusCode, string message, Exception innerExce
}

public ushort StatusCode { get; private set;}

private static string PrepareExceptionMessage(ushort statusCode)
{
return $"Exception with status code {statusCode}: {WebSocketStatusCodes.ConvertStatusCodeToString(statusCode)}";
}
}
}
36 changes: 36 additions & 0 deletions src/Fleck/WebSocketStatusCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,42 @@ public static class WebSocketStatusCodes
InvalidFramePayloadData, PolicyViolation, MessageTooBig,
MandatoryExt, InternalServerError
};

public static string ConvertStatusCodeToString(ushort statusCode)
{
switch (statusCode)
{
case 1000:
return nameof(NormalClosure);
case 1001:
return nameof(GoingAway);
case 1002:
return nameof(ProtocolError);
case 1003:
return nameof(UnsupportedDataType);
case 1005:
return nameof(NoStatusReceived);
case 1006:
return nameof(AbnormalClosure);
case 1007:
return nameof(InvalidFramePayloadData);
case 1008:
return nameof(PolicyViolation);
case 1009:
return nameof(MessageTooBig);
case 1010:
return nameof(MandatoryExt);
case 1011:
return nameof(InternalServerError);
case 1015:
return nameof(TLSHandshake);
case 3000:
return nameof(ApplicationError);

default:
throw new ArgumentException($"Unexpected status status code: {statusCode}", nameof(statusCode));
}
}
}
}