Skip to content

Commit 49373ee

Browse files
authored
fix(shadcn): better error handling (#4776)
* fix(shadcn): better error messages * chore: changeset
1 parent 078dfe6 commit 49373ee

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

.changeset/tender-insects-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"shadcn": patch
3+
---
4+
5+
better error handling

packages/shadcn/src/utils/registry/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,31 @@ async function fetchRegistry(paths: string[]) {
174174
404: "Not found",
175175
500: "Internal server error",
176176
}
177+
178+
if (response.status === 401) {
179+
throw new Error(
180+
`You are not authorized to access the component at ${highlighter.info(
181+
url
182+
)}.\nIf this is a remote registry, you may need to authenticate.`
183+
)
184+
}
185+
186+
if (response.status === 404) {
187+
throw new Error(
188+
`The component at ${highlighter.info(
189+
url
190+
)} was not found.\nIt may not exist at the registry. Please make sure it is a valid component.`
191+
)
192+
}
193+
194+
if (response.status === 403) {
195+
throw new Error(
196+
`You do not have access to the component at ${highlighter.info(
197+
url
198+
)}.\nIf this is a remote registry, you may need to authenticate or a token.`
199+
)
200+
}
201+
177202
const result = await response.json()
178203
const message =
179204
result && typeof result === "object" && "error" in result

0 commit comments

Comments
 (0)