Skip to content

Commit

Permalink
fix: check for expected error type
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 13, 2021
1 parent d17f59a commit d4f6a2f
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,11 @@ function abortFetch (p, request, responseObject) {
if (request.body !== null) {
try {
request.body.stream.cancel(error)
} catch {
// Will throw if body is not readable.
} catch (err) {
// Will throw TypeError if body is not readable.
if (err.name !== 'TypeError') {
throw err
}
}
}

Expand All @@ -243,8 +246,11 @@ function abortFetch (p, request, responseObject) {
if (response.body != null) {
try {
context.connection.controller.error(error)
} catch {
// Will throw if not readable.
} catch (err) {
// Will throw TypeError if body is not readable.
if (err.name !== 'TypeError') {
throw err
}
}
}
}
Expand Down Expand Up @@ -1476,15 +1482,21 @@ function httpNetworkFetch (
// 2. If stream is readable, error stream with an "AbortError" DOMException.
try {
connection.controller.error(new AbortError())
} catch {
// Will throw if not readable.
} catch (err) {
// Will throw TypeError if body is not readable.
if (err.name !== 'TypeError') {
throw err
}
}
} else {
// 4. Otherwise, if stream is readable, error stream with a TypeError.
try {
connection.controller.error(new TypeError('terminated'))
} catch {
// Will throw if not readable.
} catch (err) {
// Will throw TypeError if body is not readable.
if (err.name !== 'TypeError') {
throw err
}
}
}

Expand Down

0 comments on commit d4f6a2f

Please sign in to comment.