From 6ae791a3a9b69fa60aff2970e0aaef4531fa07f1 Mon Sep 17 00:00:00 2001 From: cable Date: Mon, 21 Oct 2024 13:23:48 -0700 Subject: [PATCH] fix: surface file fetch errors --- tools/diff-generator/src/lib/file-import.js | 34 ++++++++++++--------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/tools/diff-generator/src/lib/file-import.js b/tools/diff-generator/src/lib/file-import.js index 013de9a9..d7f3f11b 100644 --- a/tools/diff-generator/src/lib/file-import.js +++ b/tools/diff-generator/src/lib/file-import.js @@ -92,18 +92,24 @@ async function fetchTokens(tokenName, version, location) { version !== "latest" ? source + version.replace("@", "%40") : source + location; - return ( - await fetch(`${link}/packages/tokens/${tokenName}`, { - headers: { - Authorization: "Bearer " + githubAPIKey, // api is rate limited without a personal access token - }, - }) - ) - .json() - .then((tokens) => { - return tokens; - }) - .catch((e) => { - console.log(e); - }); + + const url = `${link}/packages/tokens/${tokenName}`; + const result = await fetch(url, { + headers: { + Authorization: "Bearer " + githubAPIKey, // api is rate limited without a personal access token + }, + }); + + if (result && result.status === 200) { + return result + .json() + .then((tokens) => { + return tokens; + }) + .catch((error) => { + console.log(error); + }); + } else { + throw new Error(url + "\n\t" + result.status + ": " + result.statusText); + } }