- From: Chris <notifications@github.com>
- Date: Wed, 28 Feb 2018 11:43:58 -0800
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/676@github.com>
Errors that originate in `ReadableStreamDefaultReader.read()` to not propagate to Promise rejections for `Response` stream reader (`Response.text()`, `Response.json()`, etc) errors.
```JavaScript
// Test 1 - ReadableStreamDefaultReader.read() error successfully propagated to catch()
new ReadableStream({
start(controller) {
// controller.close();
controller.error(Error('Test 1 Error'));
}
}).getReader().read()
.then(o => console.log('Test 1 OK', o))
.catch(error => console.error(error))
// Test 2 - ReadableStreamDefaultReader.read() error lost and unavailable to catch().
// Instead, TypeError: Failed to fetch is propagated
new Response(
new ReadableStream({
start(controller) {
// controller.enqueue(new TextEncoder().encode('hello'))
// controller.close();
controller.error(Error('Test 2 Error'));
}
})
).text()
.then(string => console.log('Test 2 OK', string))
.catch(error => console.error(error))
```
Catching the originating errors in Promise rejections would be very useful to our applications so that we could take appropriate action. For example, network errors that occur mid-download ([example](https://gist.github.com/AnthumChris/39ebe19f2f226e2858e0511febf2a002)) originate as "TypeError: network error" but are reported to the application as "TypeError: Failed to fetch". Or perhaps we want to exit early and throw an error during a custom `read()` while parsing a large remote remote file (e.g. "Invalid character at position 30").
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/676
Received on Wednesday, 28 February 2018 19:44:20 UTC