diff --git a/.changeset/tender-insects-fix.md b/.changeset/tender-insects-fix.md new file mode 100644 index 00000000000..5f7dcc51c58 --- /dev/null +++ b/.changeset/tender-insects-fix.md @@ -0,0 +1,5 @@ +--- +"shadcn": patch +--- + +better error handling diff --git a/packages/shadcn/src/utils/registry/index.ts b/packages/shadcn/src/utils/registry/index.ts index 3ae43c20792..b8d54d35b84 100644 --- a/packages/shadcn/src/utils/registry/index.ts +++ b/packages/shadcn/src/utils/registry/index.ts @@ -174,6 +174,31 @@ async function fetchRegistry(paths: string[]) { 404: "Not found", 500: "Internal server error", } + + if (response.status === 401) { + throw new Error( + `You are not authorized to access the component at ${highlighter.info( + url + )}.\nIf this is a remote registry, you may need to authenticate.` + ) + } + + if (response.status === 404) { + throw new Error( + `The component at ${highlighter.info( + url + )} was not found.\nIt may not exist at the registry. Please make sure it is a valid component.` + ) + } + + if (response.status === 403) { + throw new Error( + `You do not have access to the component at ${highlighter.info( + url + )}.\nIf this is a remote registry, you may need to authenticate or a token.` + ) + } + const result = await response.json() const message = result && typeof result === "object" && "error" in result