mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
fix(create-astro): log fetch errors (#11567)
This commit is contained in:
parent
504c383e20
commit
d27cf6df7b
2 changed files with 23 additions and 4 deletions
5
.changeset/gorgeous-timers-tease.md
Normal file
5
.changeset/gorgeous-timers-tease.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'create-astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Logs underlying error when a template cannot be downloaded
|
|
@ -83,7 +83,6 @@ export function getTemplateTarget(tmpl: string, ref = 'latest') {
|
||||||
|
|
||||||
export default async function copyTemplate(tmpl: string, ctx: Context) {
|
export default async function copyTemplate(tmpl: string, ctx: Context) {
|
||||||
const templateTarget = getTemplateTarget(tmpl, ctx.ref);
|
const templateTarget = getTemplateTarget(tmpl, ctx.ref);
|
||||||
|
|
||||||
// Copy
|
// Copy
|
||||||
if (!ctx.dryRun) {
|
if (!ctx.dryRun) {
|
||||||
try {
|
try {
|
||||||
|
@ -104,11 +103,26 @@ export default async function copyTemplate(tmpl: string, ctx: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err.message.includes('404')) {
|
if (err.message?.includes('404')) {
|
||||||
throw new Error(`Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`);
|
throw new Error(`Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`);
|
||||||
} else {
|
|
||||||
throw new Error(err.message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (err.message) {
|
||||||
|
error('error', err.message);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// The underlying error is often buried deep in the `cause` property
|
||||||
|
// This is in a try/catch block in case of weirdnesses in accessing the `cause` property
|
||||||
|
if ('cause' in err) {
|
||||||
|
// This is probably included in err.message, but we can log it just in case it has extra info
|
||||||
|
error('error', err.cause);
|
||||||
|
if ('cause' in err.cause) {
|
||||||
|
// Hopefully the actual fetch error message
|
||||||
|
error('error', err.cause?.cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
throw new Error(`Unable to download template ${color.reset(tmpl)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// It's possible the repo exists (ex. `withastro/astro`),
|
// It's possible the repo exists (ex. `withastro/astro`),
|
||||||
|
|
Loading…
Reference in a new issue