Skip to content

Commit

Permalink
fix: forward termination error
Browse files Browse the repository at this point in the history
Fixes: #1140
  • Loading branch information
ronag committed Dec 12, 2021
1 parent 1af14ae commit 47eb207
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function fetch (...args) {
if (this.terminated) {
return
}
this.terminated = { aborted }
this.terminated = { aborted, reason }

this.connection?.destroy(reason)

Expand Down Expand Up @@ -1249,11 +1249,15 @@ async function httpNetworkOrCacheFetch (
// 3. If the ongoing fetch is terminated, then:
if (context.terminated) {
// 1. Let aborted be the termination’s aborted flag.
const aborted = context.terminated.aborted

// 2. If aborted is set, then return an aborted network error.
if (aborted) {
return makeNetworkError(new AbortError())
}

// 3. Return a network error.
return makeNetworkError(
context.terminated.aborted ? new AbortError() : null
)
return makeNetworkError(context.terminated.reason)
}

// 4. Prompt the end user as appropriate in request’s window and store
Expand Down Expand Up @@ -1283,10 +1287,12 @@ async function httpNetworkOrCacheFetch (
const aborted = context.terminated.aborted

// 2. If aborted is set, then return an aborted network error.
const reason = aborted ? new AbortError() : new Error('terminated')
if (aborted) {
return makeNetworkError(new AbortError())
}

// 3. Return a network error.
return makeNetworkError(reason)
return makeNetworkError(context.terminated.reason)
}

// 2. Set response to the result of running HTTP-network-or-cache
Expand Down Expand Up @@ -1476,10 +1482,12 @@ function httpNetworkFetch (
this.connection.destroy()

// 3. If aborted is set, then return an aborted network error.
const reason = aborted ? new AbortError() : new Error('terminated')
if (aborted) {
return resolve(makeNetworkError(new AbortError()))
}

// 4. Return a network error.
resolve(makeNetworkError(reason))
return resolve(makeNetworkError(this.terminated.reason))
}

// 10. Let pullAlgorithm be an action that resumes the ongoing fetch
Expand Down

0 comments on commit 47eb207

Please sign in to comment.