From a17f8da51ddc9e57b734b5c46441cd833052ed90 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 14 May 2024 12:56:53 -0500 Subject: [PATCH] fix: add better debugging for fetch failures --- src/lib/readmeAPIFetch.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/lib/readmeAPIFetch.ts b/src/lib/readmeAPIFetch.ts index 7d0d7de30..10a64fb0b 100644 --- a/src/lib/readmeAPIFetch.ts +++ b/src/lib/readmeAPIFetch.ts @@ -190,17 +190,22 @@ export default async function readmeAPIFetch( ...options, headers, dispatcher: proxy ? new ProxyAgent(proxy) : undefined, - }).then(res => { - const warningHeader = res.headers.get('Warning'); - if (warningHeader) { - debug(`received warning header: ${warningHeader}`); - const warnings = parseWarningHeader(warningHeader); - warnings.forEach(warning => { - warn(warning.message, 'ReadMe API Warning:'); - }); - } - return res; - }); + }) + .then(res => { + const warningHeader = res.headers.get('Warning'); + if (warningHeader) { + debug(`received warning header: ${warningHeader}`); + const warnings = parseWarningHeader(warningHeader); + warnings.forEach(warning => { + warn(warning.message, 'ReadMe API Warning:'); + }); + } + return res; + }) + .catch(e => { + debug(`error making fetch request: ${e}`); + throw e; + }); } /**