Skip to content

Commit

Permalink
Show better errors when fetching ontology fails in create-template #1036
Browse files Browse the repository at this point in the history
  • Loading branch information
Polleps committed Feb 5, 2025
1 parent d97ffe1 commit e2f598d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions browser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 25 additions & 4 deletions browser/create-template/src/postprocess.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit e2f598d

Please sign in to comment.