Re: [whatwg/fetch] Attach timing info and URL to network errors, and report for fetch API (#1311)

@MattiasBuelens commented on this pull request.



> @@ -4225,6 +4258,25 @@ steps:
    <var>processBody</var>, <var>processBodyError</var>, and <var>fetchParams</var>'s
    <a for="fetch params">task destination</a>.
   </ol>
+ </li>
+
+ <li>
+  <p>Otherwise, if <var>response</var>'s <a for=response>body</a> is not null and is
+  <a for=ReadableStream>readable</a>, then:</o>
+
+  <ol>
+   <li><p>Let <var>transformStream</var> be a new a {{TransformStream}}.
+
+   <li><p>Let <var>identityTransformAlgorithm</var> be an algorithm which, given <var>chunk</var>,
+   <a for=ReadableStream lt=enqueue>enqueues</a> <var>chunk</var> in <var>transformStream</var>.

```suggestion
   <a for=TransformStream lt=enqueue>enqueues</a> <var>chunk</var> in <var>transformStream</var>.
```

> @@ -4225,6 +4258,25 @@ steps:
    <var>processBody</var>, <var>processBodyError</var>, and <var>fetchParams</var>'s
    <a for="fetch params">task destination</a>.
   </ol>
+ </li>
+
+ <li>
+  <p>Otherwise, if <var>response</var>'s <a for=response>body</a> is not null and is
+  <a for=ReadableStream>readable</a>, then:</o>
+
+  <ol>
+   <li><p>Let <var>transformStream</var> be a new a {{TransformStream}}.
+
+   <li><p>Let <var>identityTransformAlgorithm</var> be an algorithm which, given <var>chunk</var>,
+   <a for=ReadableStream lt=enqueue>enqueues</a> <var>chunk</var> in <var>transformStream</var>.
+
+   <li><p>Set <var>response</var>'s <a for=response>body</a> to the result of
+   <a for=TransformStream>setting up</a> <var>transformStream</var> with

[Set up a `TransformStream`](https://streams.spec.whatwg.org/#transformstream-set-up) doesn't return anything, so you can't set *response*'s body to its result. (Looks like "HTTP fetch" also does this wrong.) You want to do this in two steps:

1. Set up *transformStream* with *identityTransformAlgorithm* and *finalize*.
2. Set *response*'s body to *transformStream*'s `readable`.

However, it looks like Streams doesn't yet expose helpers for other specs to access the `readable` and `writable` properties of a `TransformStream`. (We should probably fix this in Streams. 🤔) 

Luckily, we don't really need to access it directly. We need to pipe *response*'s body through *transformStream* anyway, so we can use the [pipe through](https://streams.spec.whatwg.org/#readablestream-pipe-through) helper, which does this for us:

1. Set up *transformStream* with *identityTransformAlgorithm* and *finalize*.
2. Set *response*'s body to the result of piping *response*'s body through *transformStream*.

-- 
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/pull/1311#pullrequestreview-817647023

Received on Monday, 29 November 2021 13:19:34 UTC