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
Cancel request before actual request #1012
Comments
Actually this works. Throwing in a hook cancels the request.
You can use |
It does in practice, but it will call the So with the goal of mocking requests, not so much. I totally missed the Thank you! |
@sindresorhus Should it be possible to return a response from a |
@szmarczak Wouldn't it be better to allow returning a new different request from |
@sindresorhus You can already modify options in a Or we can allow returning const request = (url, options) => new Promise((resolve, reject) => {
const request = http.request(url, options);
request.once('error', () => {
resolve(createIncomingMessage());
});
request.once('socket', () => resolve(request));
});
await got(url, {request}); |
I'm not sure how modifying options helps with canceling the request? But another use-case for being able to return
I wouldn't really find that useful as I don't want to override |
#1051 allows to return an IncomingMessage (ResponseLike) instance using the I'll make |
Great 👌 |
What would you like to discuss?
I wasn't able to find this on the docs, nor can I find a way using the hooks features. I might be missing something.
I would like to cancel a request before it leaves my machine.
Example (this is not working, it might just better illustrate what I want to do):
My idea is to provide some predefined responses in some specific situations.
Any idea on how to do this?
Thanks
PS: My objective is to mock requests so it would be ideal to return the instance itself instead of using
.cancel()
Checklist
The text was updated successfully, but these errors were encountered: