From f4efd1c808476c7e60fe00fcfb86276cf14fee79 Mon Sep 17 00:00:00 2001 From: Zhang Zhipeng <414326615@qq.com> Date: Fri, 17 Nov 2023 22:28:47 +0800 Subject: [PATCH] Warn if astro add fetch failed with non 404 status (#9121) Co-authored-by: bluwy --- .changeset/brave-taxis-arrive.md | 5 +++++ packages/astro/src/cli/add/index.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/brave-taxis-arrive.md diff --git a/.changeset/brave-taxis-arrive.md b/.changeset/brave-taxis-arrive.md new file mode 100644 index 0000000000..3d2a5bd172 --- /dev/null +++ b/.changeset/brave-taxis-arrive.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Adds a warning if `astro add` fetches a package but returns a non-404 status diff --git a/packages/astro/src/cli/add/index.ts b/packages/astro/src/cli/add/index.ts index 42b1606657..80c0e10ff7 100644 --- a/packages/astro/src/cli/add/index.ts +++ b/packages/astro/src/cli/add/index.ts @@ -731,8 +731,11 @@ async function fetchPackageJson( const res = await fetch(`${registry}/${packageName}/${tag}`); if (res.status >= 200 && res.status < 300) { return await res.json(); - } else { + } else if (res.status === 404) { + // 404 means the package doesn't exist, so we don't need an error message here return new Error(); + } else { + return new Error(`Failed to fetch ${registry}/${packageName}/${tag} - GET ${res.status}`); } } @@ -754,6 +757,9 @@ export async function validateIntegrations(integrations: string[]): Promise