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: support throwing Response.error() #563

Merged
merged 1 commit into from
Apr 21, 2024
Merged

Conversation

kettanaito
Copy link
Member

Previously, throwing a Response.erorr() will fall through the instanceof Response check and be used as a mocked response. That would actually thrown an error.

Now, we have an extra check for thrown responses, if they are a Response.error(), it will result in the network error (i.e. request error) just as it does if you do request.respondWith(Response.error()).

'received network error response, erroring request...'
)

this.errorWith(new TypeError('Network 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.

This is the only difference with the RequestError. Response.error supports no error message and so it's translated to a generic Network error error.

@kettanaito kettanaito requested a review from mikicho April 21, 2024 10:08
@kettanaito kettanaito changed the title fix: support throwing Response.error() fix: support throwing Response.error() Apr 21, 2024
@@ -119,7 +127,7 @@ export function createXMLHttpRequestProxy({
mockedResponse.statusText
)

if (mockedResponse.type === '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.

Oops! Inaccessible way to check for Response.error().

@kettanaito
Copy link
Member Author

This is a bug fix so I will merge this straight away.

@kettanaito kettanaito merged commit 9dda725 into main Apr 21, 2024
2 checks passed
@kettanaito kettanaito deleted the fix/throw-response-error branch April 21, 2024 10:10
@kettanaito
Copy link
Member Author

Released: v0.28.4 🎉

This has been released in v0.28.4!

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