Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
feat: improves error messages in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Mar 23, 2020
1 parent d0c5b6f commit 083a1f8
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/cli/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { ICliFileConfig, fileHelper, getFilenameWithoutExtension, CliAction } fr
import { ExportService } from '../export';
import { IImportSource, ImportService } from '../import';
import { ZipService } from '../zip';
import { ProjectContracts } from '@kentico/kontent-management';
import { ProjectContracts, SharedModels } from '@kentico/kontent-management';

const argv = yargs.argv;

const backup = async (config: ICliFileConfig) => {
const backupAsync = async (config: ICliFileConfig) => {
const exportService = new ExportService({
apiKey: config.apiKey,
projectId: config.projectId,
Expand Down Expand Up @@ -48,7 +48,7 @@ const getLogFilename = (filename: string) => {
return`${getFilenameWithoutExtension(filename)}_log.json`;
}

const clean = async (config: ICliFileConfig) => {
const cleanAsync = async (config: ICliFileConfig) => {
const cleanService = new CleanService({
onDelete: item => {
if (config.enableLog) {
Expand All @@ -64,7 +64,7 @@ const clean = async (config: ICliFileConfig) => {
console.log('Completed');
};

const restore = async (config: ICliFileConfig) => {
const restoreAsync = async (config: ICliFileConfig) => {
const zipService = new ZipService({
filename: config.zipFilename,
enableLog: config.enableLog
Expand Down Expand Up @@ -133,11 +133,11 @@ const process = async () => {
validateConfig(config);

if (config.action === 'backup') {
backup(config);
await backupAsync(config);
} else if (config.action === 'clean') {
clean(config);
await cleanAsync(config);
} else if (config.action === 'restore') {
restore(config);
await restoreAsync(config);
} else {
throw Error(`Invalid action`);
}
Expand Down Expand Up @@ -217,4 +217,13 @@ const getDefaultBackupFilename = () => {
return `kontent-backup-${date.getDate()}-${date.getMonth() + 1}-${date.getFullYear()}-${date.getHours()}-${date.getMinutes()}`;
}

process();
process().then(m => {}).catch(err => {
if (err instanceof SharedModels.ContentManagementBaseKontentError) {
console.log(`Management API error occured:`, err.message);
for (const validationError of err.validationErrors) {
console.log(validationError.message);
}
} else {
console.log(`There was an error processing your request: `, err);
}
});

0 comments on commit 083a1f8

Please sign in to comment.