Skip to content

fix(nestjs): treat WsException as expected error#19640

Open
7inspire wants to merge 1 commit intogetsentry:developfrom
7inspire:codex/fix-19631-ws-exception-filter
Open

fix(nestjs): treat WsException as expected error#19640
7inspire wants to merge 1 commit intogetsentry:developfrom
7inspire:codex/fix-19631-ws-exception-filter

Conversation

@7inspire
Copy link
Contributor

@7inspire 7inspire commented Mar 5, 2026

This PR updates NestJS expected-error detection to avoid reporting WsException control-flow errors to Sentry.

Why

Issue #19631 notes that WsException should be treated similarly to HttpException and RpcException (control-flow exceptions thrown by user code), and should not be captured as errors.

What changed

  • Updated isExpectedError in packages/nestjs/src/helpers.ts:
    • Keep existing getError + initMessage detection (covers current RpcException/WsException shapes).
    • Add a WsException fallback for variants that expose getError but not initMessage, detected via constructor.name === 'WsException'.
  • Added test coverage in packages/nestjs/test/helpers.test.ts for a WsException-like object without initMessage.

Risk

Low. The change is scoped to NestJS control-flow exception classification and does not alter event pipeline behavior outside this filter.

Validation

  • Added unit test for the new WsException fallback case.
  • Note: Full test execution was not run in this environment because yarn is unavailable.

@nicohrubec nicohrubec self-requested a review March 5, 2026 09:10
}

// WsException fallback (older/custom variants may not expose initMessage)
if (typeof ex.getError === 'function' && ex.constructor?.name === 'WsException') {
Copy link
Member

@nicohrubec nicohrubec Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants