From e2f598de962f91660689c636702fc172593a8e45 Mon Sep 17 00:00:00 2001 From: Polle Pas Date: Tue, 4 Feb 2025 16:27:59 +0100 Subject: [PATCH] Show better errors when fetching ontology fails in create-template #1036 --- browser/CHANGELOG.md | 1 + browser/create-template/src/postprocess.ts | 29 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/browser/CHANGELOG.md b/browser/CHANGELOG.md index cd92052a..97cd05a6 100644 --- a/browser/CHANGELOG.md +++ b/browser/CHANGELOG.md @@ -54,6 +54,7 @@ This changelog covers all five packages, as they are (for now) updated as a whol - [#700](https://github.com/atomicdata-dev/atomic-server/issues/700) Update SvelteKit-site template to Svelte 5 and the new @tomic/svelte. - [#966](https://github.com/atomicdata-dev/atomic-server/issues/966) Add NextJS template. +- [#1036](https://github.com/atomicdata-dev/atomic-server/issues/1036) Provide clearer errors when resources couldn't be fetched. - [#993](https://github.com/atomicdata-dev/atomic-server/issues/993) Fix template not working when the drive subject has a path after the origin. ## [v0.40.0] - 2024-10-07 diff --git a/browser/create-template/src/postprocess.ts b/browser/create-template/src/postprocess.ts index 8094d732..9596078e 100644 --- a/browser/create-template/src/postprocess.ts +++ b/browser/create-template/src/postprocess.ts @@ -1,6 +1,6 @@ import path from 'node:path'; import fs from 'node:fs'; -import { Store, type Resource } from '@tomic/lib'; +import { ErrorType, isAtomicError, Store, type Resource } from '@tomic/lib'; import { type ExecutionContext, type TemplateKey, @@ -31,9 +31,30 @@ export async function postProcess(context: PostProcessContext) { const ontology = await store.getResource(ontologySubject); if (ontology.error) { - console.error( - `\nThe ${baseTemplate.name} template does not exist on your drive. To get the template go to the Create Resource page and select the ${baseTemplate.name} template`, - ); + if (isAtomicError(ontology.error)) { + switch (ontology.error.type) { + case ErrorType.NotFound: + console.error( + `\nThe ${baseTemplate.name} template does not exist on your drive. To get the template go to the Create Resource page and select the ${baseTemplate.name} template`, + ); + break; + case ErrorType.Unauthorized: + console.error( + '\nSome of the template resources could not be accessed. Make sure the resources are public.', + ); + break; + case ErrorType.Server: + console.error( + '\nServer Error: Something went wrong while fetching the template.', + ); + break; + default: + console.error('\nAn error occurred while fetching the template.'); + } + } else { + console.error(ontology.error.message); + } + process.exit(1); }