From cece2e7d75da007857c7f830efb6395d1ebb172e Mon Sep 17 00:00:00 2001 From: Pablo Olavarrieta Date: Fri, 4 Oct 2024 20:52:28 -0700 Subject: [PATCH] fix: catch and reject with error if new Response throws inside resolve --- fetch.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fetch.js b/fetch.js index f39a983a..48263fff 100644 --- a/fetch.js +++ b/fetch.js @@ -551,8 +551,10 @@ export function fetch(input, init) { } options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL') var body = 'response' in xhr ? xhr.response : xhr.responseText - setTimeout(function() { - resolve(new Response(body, options)) + setTimeout(function () { + try { + resolve(new Response(body, options)) + } catch (e) { reject(e) } }, 0) }