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: treat unhandled interceptor exceptions as 500 responses #532

Merged
merged 5 commits into from
Apr 16, 2024

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Mar 26, 2024

Much like request handlers in MSW, everything you write in your interceptors is from the server's perspective. If an exception happens on the server, it's usually handled gracefully as the 500 error response to the client. This consistency is nice for predictability but also aligned behavior across the low-level Interceptors and high-level MSW.

Changes

  • Any exceptions thrown in the request listeners are now coerced to 500 Unhandled Exception mocked error response to emulate server suffering an exception.
  • To mock request errors, do request.respondWith(Response.error()).

@kettanaito kettanaito requested a review from mattcosta7 March 26, 2024 12:36
@kettanaito kettanaito force-pushed the feat/exceptions-as-500-responses branch from 3d5bce3 to 443262e Compare April 16, 2024 17:09
@kettanaito kettanaito merged commit 61f9459 into main Apr 16, 2024
2 checks passed
@kettanaito kettanaito deleted the feat/exceptions-as-500-responses branch April 16, 2024 17:14
@kettanaito
Copy link
Member Author

Released: v0.28.0 🎉

This has been released in v0.28.0!

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.

Treat exceptions as 500 responses instead of a "Failed to fetch" error
1 participant