question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Emitting an error event throws an exception

See original GitHub issue

Bug 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:closed
  • Created 4 years ago
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
THPubscommented, Sep 17, 2019

@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) 🙂

1reaction
THPubscommented, Sep 17, 2019

@izio38 Sure you can have a look at this repo: https://github.com/THPubs/nest-ws

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found