From 2544a5deac6707171a798eeacd7018a2a8c29e70 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Wed, 19 May 2021 01:50:35 +0100 Subject: [PATCH] Handle aborts during json parsing --- src/api.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api.ts b/src/api.ts index b8ee146..ab4f2ca 100644 --- a/src/api.ts +++ b/src/api.ts @@ -669,7 +669,12 @@ async function fetchJSON(url: string, signal: AbortSignal) { try { json = await response.json(); } catch(e) { - throw new Error('Request returned invalid json'); + if(e instanceof DOMException && e.name === 'AbortError') { + console.warn(`Request aborted (${url}`); + throw e; + } else { + throw new Error('Request returned invalid json'); + } } return json;