From ac6983f5d87d0b59ce8f22a4e131facb1dc39ab4 Mon Sep 17 00:00:00 2001 From: Jayant Kumar <75439864+Jayk5@users.noreply.github.com> Date: Tue, 20 Jun 2023 03:13:41 +0530 Subject: [PATCH] fix: add warning instead of error message on redeploying an app-config (#174) --- src/commands/app-configs/deploy.ts | 16 ++++++++++++++++ test/commands/app-configs/deploy.test.ts | 9 ++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/commands/app-configs/deploy.ts b/src/commands/app-configs/deploy.ts index 47a9b552..85cefd5d 100644 --- a/src/commands/app-configs/deploy.ts +++ b/src/commands/app-configs/deploy.ts @@ -14,6 +14,9 @@ import * as MixFlags from '../../utils/flags' import MixCommand from '../../utils/base/mix-command' import {AppConfigsDeployParams, MixClient, MixResponse, MixResult} from '../../mix/types' import {DomainOption} from '../../utils/validations' +import {MixError} from '../../mix/types' +import {CliUx} from '@oclif/core' +import chalk from 'chalk' const debug = makeDebug('mix:commands:app-configs:deploy') @@ -97,4 +100,17 @@ the application configuration was created. const data = result.data as any return data.deployments } + + // Show a warning if a user tries to deploy an app-config when it is already deployed + handleError(error: MixError) { + debug('handleError() error.statusCode: %d', error.statusCode) + + if (error.statusCode === 400 && error.message.toLocaleLowerCase().includes('deployment already completed')) { + CliUx.ux.action.stop(chalk.yellow('Aborted')) + this.warn(`Application configuration was already deployed. +It is not possible to re-deploy an already deployed application configuration.`) + } else { + super.handleError(error) + } + } } diff --git a/test/commands/app-configs/deploy.test.ts b/test/commands/app-configs/deploy.test.ts index e0e66adb..46c01b42 100644 --- a/test/commands/app-configs/deploy.test.ts +++ b/test/commands/app-configs/deploy.test.ts @@ -55,11 +55,10 @@ describe('app-configs:deploy', () => { .put(endpoint) .reply(400, td.deploy.response400) ) - .stdout() + .stderr() .command(['app-configs:deploy','-C', config]) - .catch(ctx => { - expect(ctx.message).to.contain('Deployment already completed') - }) - .it('fails if app config is already deployed', ctx => { + .it('fails if app config is already deployed and shows warning', ctx => { + const [firstLine] = ctx.stderr.split('\n') + expect(firstLine).to.contain('configuration was already deployed') }) })