bun
bun copied to clipboard
Catch doesn't works as expected with AbortController
What version of Bun is running?
1.0.36+40f61ebb9
What platform is your computer?
Darwin 23.4.0 arm64 arm
What steps can reproduce the bug?
When I use fetch
and then receive response as a stream and then abort the request, the catch does not work as expected:
Request was aborted
Test completed
AbortError: The operation was aborted.
The third line AbortError: The operation was aborted.
is NOT expected! Especially after the Test completed
is shown...
Code for repro:
const abortController = new AbortController();
async function test() {
try {
const response = await fetch('https://bun.sh/', {
signal: abortController.signal
});
const stream = response.body;
// @ts-ignore
for await (const part of stream) {
abortController.abort();
}
} catch (e: any) {
if (e.name === 'AbortError') {
console.log('Request was aborted');
} else {
console.error('An error occurred', e);
}
}
console.log('Test completed');
}
test();
What is the expected behavior?
There should not be the AbortError: The operation was aborted.
, because there is try/catch around the fetch.
What do you see instead?
No response
Additional information
No response