dotnet / dotnet/aspnetcore

Pass websocket closeEvent.code in `WebSocketTransport` onClose event to consumer via new error type WebSocketError

Open
#57,258 0 comments 0 reactions 0 assignees View on GitHub
area-signalr
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

I am trying to handle WebSocket disconnections reliably in my SignalR client. However, the current implementation of the [WebSocketTransport](https://github.com/dotnet/aspnetcore/blob/9518cf2c2152b9406efccd928d90e67793065dbe/src/SignalR/clients/ts/signalr/src/WebSocketTransport.ts#L177) in the SignalR TypeScript client SDK does not pass the `closeEvent.code` to the consumer. This makes it difficult to distinguish between different types of disconnections and act accordingly, as the essential information provided by the WebSocket close event code is not accessible.

### Describe the solution you'd like

I propose introducing a new error type, `WebSocketError`, which extends the `Error` class. This error should capture the `wasClean` and code fields from the `closeEvent`, similar to how the SDK currently handles `HttpError` in [Errors.ts](https://github.com/dotnet/aspnetcore/blob/9518cf2c2152b9406efccd928d90e67793065dbe/src/SignalR/clients/ts/signalr/src/Errors.ts#L7) . This would allow consumers of the SDK to access these fields and handle WebSocket disconnections based on the specific close event code.

### Additional context

You can find the current implementation in the following code references:
- [WebSocketTransport.ts](https://github.com/dotnet/aspnetcore/blob/9518cf2c2152b9406efccd928d90e67793065dbe/src/SignalR/clients/ts/signalr/src/WebSocketTransport.ts#L176)
- [HttpError in Errors.ts](https://github.com/dotnet/aspnetcore/blob/9518cf2c2152b9406efccd928d90e67793065dbe/src/SignalR/clients/ts/signalr/src/Errors.ts#L7)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.