feat(nestjs): Support WebSocket errors in SentryGlobalFilter#22224
Open
psh4607 wants to merge 6 commits into
Open
feat(nestjs): Support WebSocket errors in SentryGlobalFilter#22224psh4607 wants to merge 6 commits into
psh4607 wants to merge 6 commits into
Conversation
6d29b23 to
b67f4e8
Compare
e066783 to
6b0be86
Compare
chargome
reviewed
Jul 15, 2026
chargome
left a comment
Member
There was a problem hiding this comment.
Looks good overall, just some minor nits.
|
|
||
| expect(error.exception?.values?.[0]).toMatchObject({ | ||
| type: 'Error', | ||
| value: 'This is an exception in a WebSocket handler', |
Member
There was a problem hiding this comment.
Suggested change
| value: 'This is an exception in a WebSocket handler', | |
| value: 'This is an exception in a WebSocket handler', | |
| mechanism: { | |
| handled: false, | |
| type: 'auto.ws.nestjs.global_filter', | |
| }, |
| }); | ||
| } | ||
|
|
||
| const client = host.switchToWs().getClient<{ emit: (event: string, data: unknown) => void }>(); |
Member
There was a problem hiding this comment.
Suggested change
| const client = host.switchToWs().getClient<{ emit: (event: string, data: unknown) => void }>(); | |
| const client = host.switchToWs().getClient<{ emit?: (event: string, data: unknown) => void }>(); |
Let's put the emit function optional here, in case a user uses a ws adapter that is not compatible to this interface.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint) & (yarn test).Fixes #16067
SentryGlobalFilternow handles WebSocket exceptions without delegating them to Nest's HTTPBaseExceptionFilter.Unexpected gateway errors are captured with the
auto.ws.nestjs.global_filtermechanism and emit a generic error response. ExpectedWsExceptionresponses are preserved without being reported to Sentry.WsExceptionis detected by shape so@nestjs/websocketsdoes not become a required dependency.Unit and NestJS WebSocket E2E coverage was added for unexpected errors, expected
WsExceptionvalues, and HTTP exceptions raised in a WebSocket context.Root cause: WebSocket exceptions were delegated to an HTTP exception filter which expects an HTTP adapter and cannot correctly respond through a WebSocket client.