From d4f6a2f0f60600d963e45d960d7fd7e7ce10b7d8 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 13 Aug 2021 11:18:35 +0200 Subject: [PATCH] fix: check for expected error type --- lib/fetch/index.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index e6996dddf88..f9c350f6aa9 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -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 + } } } @@ -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 + } } } } @@ -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 + } } }