Closed iamFIREcracker closed 2 years ago
I have a @Sse handler which optionally throws an UnauthorizedException, and when it does it, the exception gets serialized and sent to the client as a server-sent event
That's the expected behavior.
Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.
Is there an existing issue for this?
Current behavior
I have a
@Sse
handler which optionally throws anUnauthorizedException
, and when it does it, the exception gets serialized and sent to the client as a server-sent event; however, shouldn't Nest simply close the connection and send the serialized exception within the body of the response? Otherwise I am afraid there migth be the risk of un-authorized requests consuming server resources.Minimum reproduction code
https://github.com/iamFIREcracker/nestjs-sse-error-min-reproduction
Steps to reproduce
npm ci
npm run start:dev
curl -v http://127.0.0.1:3000/sse
Expected behavior
I would expect the server to close the connection with a 401 status code:
What happens instead, the exception gets serialized as server-sent event, and the connection left open:
Package
Other package
class-transformer
NestJS version
8.4.6
Packages versions
Node.js version
18.1.0
In which operating systems have you tested?
Other
With version
8.2.3
the situation is even worse, given that anUnauthorizedException
will cause the application to crash.