Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(WebSocket): treat interceptor exceptions as closures with error #609

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

kettanaito
Copy link
Member

While testing the onUnhandledException event in MSW, I noticed that unhandled exceptions in the connection listener are thrown on the entire process and are uncatchable. That's caused by the connection event being emitted in the queueMicrotask in the WebSocket interceptor. The queuing itself is correct.

I'm solving this by catching those interceptor exceptions and translating them to WebSocket connection closure with error. This means an unhandled interceptor exception will trigger error and close events, and also print the caught error to stderr.

* closures with error. This prevents from the exceptions occurring
* in `queueMicrotask` from being process-wide and uncatchable.
*/
if (error instanceof Error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Ignore non-errors being thrown.

@kettanaito kettanaito merged commit ca522a3 into main Aug 6, 2024
2 checks passed
@kettanaito kettanaito deleted the fix/ws-interceptor-exception branch August 6, 2024 12:14
@kettanaito
Copy link
Member Author

Released: v0.34.1 🎉

This has been released in v0.34.1!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

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.

1 participant