WebSocketError Class
- Experimental (WEBPLATEXP0027)
The error of a WebSocketStream (https://whatpr.org/websockets/48.html#the-websocketerror-interface): a DomException named WebSocketError, with the status code and the reason of the closing handshake. The promises and the streams of a WebSocketStream are rejected with a WebSocketError when the connection cannot be established or is not closed cleanly, and a WebSocketError given to cancel() or abort() of its streams gives the status code and the reason of the Close frame.
[Experimental("WEBPLATEXP0027", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public sealed class WebSocketError : DomException- Inheritance
DomExceptionWebSocketError
Constructors
| Name | Description |
|---|---|
| WebSocketError() | Creates an error with an empty message, without status code and with an empty reason. |
| WebSocketError(string?) | Creates an error with a message, without status code and with an empty reason. |
| WebSocketError(string, WebSocketCloseInfo?) | Creates an error with a message, a status code and a reason (https://whatpr.org/websockets/48.html#dom-websocketerror-websocketerror): a reason without status code gives the 1000 status code. |
| WebSocketError(string?, Exception?) | Creates a WebSocketError with a message and an inner exception. |
WebSocketError overloads
WebSocketError()
WebSocketError.csCreates an error with an empty message, without status code and with an empty reason.
public WebSocketError()WebSocketError(string?)
WebSocketError.csWebSocketError(string, WebSocketCloseInfo?)
WebSocketError.csCreates an error with a message, a status code and a reason (https://whatpr.org/websockets/48.html#dom-websocketerror-websocketerror): a reason without status code gives the 1000 status code.
public WebSocketError(string message, WebSocketCloseInfo? init)Parameters
messagestring- The message.
initWebSocketCloseInfo?- The status code (
1000or a code from3000to4999) and the reason (at most 123 bytes in UTF-8).
Exceptions
DomException- An
InvalidAccessErrorwhen the status code is not valid, or aSyntaxErrorwhen the reason is too long.
See also
WebSocketError(string?, Exception?)
WebSocketError.csCreates a WebSocketError with a message and an inner exception.
Parameters
messagestring?- The message.
innerExceptionException?- The exception that caused the error.
Properties
| Name | Description |
|---|---|
| CloseCode | Gets the status code of the closing handshake, or null. |
| Reason | Gets the reason of the closing handshake, or the empty string. |
CloseCode
WebSocketError.csGets the status code of the closing handshake, or null.
public ushort? CloseCode { get; }Reason
WebSocketError.csGets the reason of the closing handshake, or the empty string.
public string Reason { get; }