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
DomException WebSocketError

Constructors

NameDescription
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.cs

Creates an error with an empty message, without status code and with an empty reason.

public WebSocketError()

WebSocketError(string?)

WebSocketError.cs

Creates an error with a message, without status code and with an empty reason.

public WebSocketError(string? message)

WebSocketError(string, WebSocketCloseInfo?)

WebSocketError.cs

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.

public WebSocketError(string message, WebSocketCloseInfo? init)
Parameters
message string
The message.
init WebSocketCloseInfo?
The status code (1000 or a code from 3000 to 4999) and the reason (at most 123 bytes in UTF-8).
Exceptions
DomException
An InvalidAccessError when the status code is not valid, or a SyntaxError when the reason is too long.
See also

WebSocketError(string?, Exception?)

WebSocketError.cs

Creates a WebSocketError with a message and an inner exception.

public WebSocketError(string? message, Exception? innerException)
Parameters
message string?
The message.
innerException Exception?
The exception that caused the error.

Properties

NameDescription
CloseCodeGets the status code of the closing handshake, or null.
ReasonGets the reason of the closing handshake, or the empty string.

Gets the status code of the closing handshake, or null.

public ushort? CloseCode { get; }

Gets the reason of the closing handshake, or the empty string.

public string Reason { get; }