nest
nest copied to clipboard
feat(common): Make ValidationPipe aware of WebSocket context
Extended logic of UsePipes and ValidationPipe decorators to give awareness of WebSocket context.
Closes #13190
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
- [x] Tests for the changes have been added (for bug fixes / features)
- [x] Docs have been added / updated (for bug fixes / features)
PR Type
This PR makes the ValidationPipe aware of being used in a WebSocket context. It is now correctly throwing a WsException instead of an internal server error when validation fails. It also moved the WsException into the common package, which is being referenced from the websockets package now.
- [ ] Bugfix
- [x] Feature
- [ ] Code style update (formatting, local variables)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] CI related changes
- [ ] Other... Please describe:
What is the current behavior?
Issue Number: 13190
What is the new behavior?
ValidationPipe now correctly returns WsException with validation error details when validation in WebSocket gateway is failing.
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
This is my first open source contribution and I hope I adhered to all guidelines correctly.
Pull Request Test Coverage Report for Build cb257d08-6615-4066-aa8e-e15f3c7fd5ee
Details
- -8 of 31 (74.19%) changed or added relevant lines in 8 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage decreased (-0.08%) to 92.079%
| Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
|---|---|---|---|
| packages/common/decorators/core/use-pipes.decorator.ts | 3 | 4 | 75.0% |
| packages/common/pipes/validation.pipe.ts | 11 | 18 | 61.11% |
| <!-- | Total: | 23 | 31 |
| Totals | |
|---|---|
| Change from base Build 086b893a-64dc-49ed-b1bd-71bc94aca6ea: | -0.08% |
| Covered Lines: | 6742 |
| Relevant Lines: | 7322 |