fix(nestjs): treat WsException as expected error#19640
Open
7inspire wants to merge 1 commit intogetsentry:developfrom
Open
fix(nestjs): treat WsException as expected error#196407inspire wants to merge 1 commit intogetsentry:developfrom
7inspire wants to merge 1 commit intogetsentry:developfrom
Conversation
nicohrubec
reviewed
Mar 5, 2026
| } | ||
|
|
||
| // WsException fallback (older/custom variants may not expose initMessage) | ||
| if (typeof ex.getError === 'function' && ex.constructor?.name === 'WsException') { |
Member
There was a problem hiding this comment.
Why do you think we need this? Did you find any old version specifically that would require this fallback? Else we will likely close this, because it seems to be already covered by our current logic since WsException and RpcException expose basically the same 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.
This PR updates NestJS expected-error detection to avoid reporting
WsExceptioncontrol-flow errors to Sentry.Why
Issue #19631 notes that
WsExceptionshould be treated similarly toHttpExceptionandRpcException(control-flow exceptions thrown by user code), and should not be captured as errors.What changed
isExpectedErrorinpackages/nestjs/src/helpers.ts:getError + initMessagedetection (covers currentRpcException/WsExceptionshapes).WsExceptionfallback for variants that exposegetErrorbut notinitMessage, detected viaconstructor.name === 'WsException'.packages/nestjs/test/helpers.test.tsfor aWsException-like object withoutinitMessage.Risk
Low. The change is scoped to NestJS control-flow exception classification and does not alter event pipeline behavior outside this filter.
Validation
WsExceptionfallback case.yarnis unavailable.