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

feat: add "unhandledException" life-cycle event #1199

Merged
merged 1 commit into from May 2, 2022
Merged

feat: add "unhandledException" life-cycle event #1199

merged 1 commit into from May 2, 2022

Conversation

MartinJaskulla
Copy link
Contributor

@MartinJaskulla MartinJaskulla commented Apr 11, 2022

Users can now react to errors thrown in their RequestHandlers. Before this PR all errors were silently converted into a 500 response (only in the browser). Now users can subscribe to a new event:

worker.events.on('unhandledException', (error, request) => {})

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 11, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c29ffaa:

Sandbox Source
MSW React Configuration

@MartinJaskulla MartinJaskulla marked this pull request as ready for review April 11, 2022 20:13
src/sharedOptions.ts Outdated Show resolved Hide resolved
@@ -50,6 +53,12 @@ beforeAll(async () => {
listener(`[request:unhandled] ${req.method} ${req.url.href} ${req.id}`)
})

server.events.on('request:unhandledException', (req, handler, error) => {
Copy link
Member

Choose a reason for hiding this comment

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

I don't like the way I've modeled these tests in the past. Instead of invoking a listener in this callback function's body, I should've passed the listener as the callback itself. This would allow us to assert all arguments passed along a particular event.

server.events.on('foo', listener)

expect(listener).toHaveBeenCalledWith([mockedRequest, handler, error])

Let's refactor this after this feature 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am on vacation until 25.04. Will refactor it afterwards 👍

Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

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

Hey, @MartinJaskulla! Thank you for your work on this, it looks superb!

I had only one substantial comment about the order of arguments in the listener. I'd like to hear your opinion on that.

@MartinJaskulla
Copy link
Contributor Author

MartinJaskulla commented Apr 13, 2022

Hey, @MartinJaskulla! Thank you for your work on this, it looks superb!

I had only one substantial comment about the order of arguments in the listener. I'd like to hear your opinion on that.

Thank you for your support! Learning a lot 🥳

And yes, errors as the first argument make sense!

@kettanaito
Copy link
Member

Hey, @MartinJaskulla. I've force-pushed to your feature branch because we've reverted a significant chunk of one change, which made rebasing utterly impossible. I've tried to replicate your changes, so it should be okay now!

@kettanaito kettanaito changed the title feat: Add 'request:unhandledException' to LifeCycleEventsMap. feat: add 'unhandledException' life-cycle event May 1, 2022
@kettanaito kettanaito changed the title feat: add 'unhandledException' life-cycle event feat: add "unhandledException" life-cycle event May 1, 2022
@kettanaito kettanaito merged commit 1a36ada into mswjs:main May 2, 2022
@kettanaito
Copy link
Member

Welcome to the contributors, @MartinJaskulla! 🎉
I can't wait to get this to our users.

@kettanaito
Copy link
Member

Released: v0.40.0 🎉

This has been released in v0.40.0!

Make sure to always update to the latest version (npm i msw@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.

Add way to detect and log exceptions in request handlers.
2 participants