Skip to content

Commit

Permalink
Enhanced error message display (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
colodenn authored Jan 24, 2025
1 parent 8a4fdfc commit 388ccb2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/commands/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ export default async (
spinner.succeed('Successfully applied migration');
process.exit(0);
} catch (err) {
const message =
err instanceof RoninError
? err.message
: `Failed to apply migration: ${err instanceof Error ? err.message : err}`;
const message = err instanceof RoninError ? err.message : 'Failed to apply migration';
spinner.fail(message);
spinner.fail(err instanceof Error ? err.message : String(err));

process.exit(1);
}
Expand All @@ -95,7 +93,7 @@ const applyMigrationStatements = async (

spinner.info('Applying migration to production database');

await fetch(`https://data.ronin.co/?data-selector=${slug}`, {
const response = await fetch(`https://data.ronin.co/?data-selector=${slug}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -108,4 +106,10 @@ const applyMigrationStatements = async (
})),
}),
});

const result = (await response.json()) as { error: { message: string } };

if (!response.ok) {
throw new Error(result.error.message);
}
};
2 changes: 1 addition & 1 deletion src/utils/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const diffFields = async (
rename ||
(await confirm({
message: `Did you mean to rename field: ${field.from.slug} -> ${field.to.slug}`,
default: false,
default: true,
}));

if (confirmRename) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const diffModels = async (
(process.env.NODE_ENV !== 'test' &&
(await confirm({
message: `Did you mean to rename model: ${model.from.slug} -> ${model.to.slug}`,
default: false,
default: true,
})));

if (confirmRename) {
Expand Down

0 comments on commit 388ccb2

Please sign in to comment.