Emitting an error event throws an exception
See original GitHub issueBug Report
Current behaviour
If you emit an error
event in a web socket gateway:
socket.emit('error', 'un-authorized');
it throws an unhandled exception like this:
UnhandledPromiseRejectionWarning: Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('un-authorized')
The same thing happens even if we throw a WsException
:
throw new WsException('un-authorized');
The error doesn’t get forwarded to the client. The client is set to listen to this error event, get the message and show it to the user.
Expected behavior
Forwarding the error
event to the client which triggers the on error event.
Environment
Nest version: 6.7.1
For Tooling issues:
- Node version: 10.16.0
- Platform: Mac
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (2 by maintainers)
Top Results From Across the Web
How to catch an error on an eventEmitter that runs an async ...
I am able to catch errors when a synchronous function is called by the eventEmitter but unable. to catch errors when async functions...
Read more >Node.js Streams Inherit Error-Handling Behavior From ...
Ben Nadel demonstrates that the error handling behavior in Node.js streams is inherited from the EventEmitter module.
Read more >Node.js Error Handling Best Practices - Sematext
Learn what is Node.js error handling and why do you need it. From using middleware to catching uncaught exceptions, discover the best ways ......
Read more >Error handling with reactive streams. | by Kalpa Senanayake
Here in this post we are going to discuss various error handling mechanisms offered through reactive stream fluent APIs. For this example we...
Read more >A Comprehensive Guide To Error Handling In Node.js
The uncaughtException event is emitted when an exception thrown somewhere in the application is not caught before it reaches the event loop. If ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@izio38 Thanks I tried to listen to the
exception
event in both client and server. Still nothing. I just need to get the error message to the front end (client) 🙂@izio38 Sure you can have a look at this repo: https://github.com/THPubs/nest-ws