@@ -742,30 +742,44 @@ function finalizeResponse (fetchParams, response) {
742742function fetchFinale ( fetchParams , response ) {
743743 const context = this
744744
745- // 1. If fetchParams’s process response is non-null,
746- // then queue a fetch task to run fetchParams’s process response
747- // given response, with fetchParams’s task destination.
745+ // 1. If response is a network error, then:
746+ if ( response . type === 'error' ) {
747+ // 1. Set response’s URL list to « fetchParams’s request’s URL list[0] ».
748+ response . urlList = [ fetchParams . request . urlList [ 0 ] ]
749+
750+ // 2. Set response’s timing info to the result of creating an opaque timing
751+ // info for fetchParams’s timing info.
752+ response . timingInfo = createOpaqueTimingInfo ( {
753+ startTime : fetchParams . timingInfo . startTime
754+ } )
755+ }
756+
757+ // 2. Let processResponseEndOfBody be the following steps:
758+ // TODO
759+
760+ // 3. If fetchParams’s process response is non-null, then queue a fetch task
761+ // to run fetchParams’s process response given response, with fetchParams’s
762+ // task destination.
748763 if ( fetchParams . processResponse != null ) {
749764 fetchParams . processResponse ( response )
750765 }
751766
752- // 2. If fetchParams’s process response consume is non-null, then:.
753- // TODO
754- // 1. Let processBody given nullOrBytes be this step: run fetchParams’s
755- // process response consume given response and nullOrBytes.on.
756- // TODO
757- // 2. Let processBodyError be this step: run fetchParams’s process
758- // response consume given response and failure.on.
759- // TODO
760- // 3. If response’s body is null, then queue a fetch task to run
761- // processBody given null, with fetchParams’s task destination.on.
762- // TODO
763- // 4. Otherwise, fully read response’s body given processBody,
764- // processBodyError, and fetchParams’s task destination.on.
765- // TODO
766-
767- // TODO (spec): The spec doesn't specify this but we need to
768- // terminate fetch if we have an error response.
767+ // 4. If fetchParams’s process response is non-null, then queue a fetch task
768+ // to run fetchParams’s process response given response, with fetchParams’s
769+ // task destination.
770+ // TODO
771+
772+ // 5. If response’s body is null, then run processResponseEndOfBody.
773+ // TODO
774+
775+ // 6. Otherwise:
776+ // TODO
777+
778+ // 7. If fetchParams’s process response consume body is non-null, then:
779+ // TODO
780+
781+ // TODO: This is a workaround. Until the above has been implemented, i.e.
782+ // we need to either fully consume the body or terminate the fetch.
769783 if ( response . type === 'error' ) {
770784 context . terminate ( { reason : response . error } )
771785 }
0 commit comments