feat(cli): handle registry fetching errors
This commit adds error handling for fetching operations from the registry in the CLI 'list' command. Now, any failure in retrieving the registry results in a failed spinner with a clear descriptive message, thus making the failure more apparent to the user.
This commit is contained in:
parent
36c5def5a6
commit
acca348e1e
@ -22,10 +22,15 @@ export default class List extends Command {
|
|||||||
const registrySpinner = ora('Fetching registry...')
|
const registrySpinner = ora('Fetching registry...')
|
||||||
const getInstalledSpinner = ora('Getting installed components...')
|
const getInstalledSpinner = ora('Getting installed components...')
|
||||||
|
|
||||||
const loadedConfig = await validateConfig(await loadConfig(flags.config))
|
const loadedConfig = await validateConfig(this.log, await loadConfig(flags.config))
|
||||||
|
|
||||||
registrySpinner.start()
|
registrySpinner.start()
|
||||||
const registry = await getRegistry()
|
const unsafeRegistry = await getRegistry()
|
||||||
|
if (!unsafeRegistry.ok) {
|
||||||
|
registrySpinner.fail(unsafeRegistry.message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const registry = unsafeRegistry.registry
|
||||||
registrySpinner.succeed(`Fetched ${Object.keys(registry.components).length} components.`)
|
registrySpinner.succeed(`Fetched ${Object.keys(registry.components).length} components.`)
|
||||||
|
|
||||||
const names = await getAvailableComponentNames(registry)
|
const names = await getAvailableComponentNames(registry)
|
||||||
|
@ -1,7 +1,19 @@
|
|||||||
import {REGISTRY_URL, Registry} from '../const.js'
|
import {REGISTRY_URL, Registry} from '../const.js'
|
||||||
|
|
||||||
export async function getRegistry(): Promise<Registry> {
|
export async function getRegistry(): Promise<{ok: true; registry: Registry} | {ok: false; message: string}> {
|
||||||
return (await (await fetch(REGISTRY_URL)).json()) as Registry
|
const registryResponse = await fetch(REGISTRY_URL)
|
||||||
|
|
||||||
|
if (registryResponse.ok) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
registry: (await registryResponse.json()) as Registry,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
message: `Error while fetching registry: ${registryResponse.status} ${registryResponse.statusText}`,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAvailableComponentNames(registry: Registry): Promise<string[]> {
|
export async function getAvailableComponentNames(registry: Registry): Promise<string[]> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user