Skip to content

Commit

Permalink
fix: add warning instead of error message on redeploying an app-config (
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayk5 committed Jun 19, 2023
1 parent 2f3ce6a commit ac6983f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/commands/app-configs/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
}
}
}
9 changes: 4 additions & 5 deletions test/commands/app-configs/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit ac6983f

Please sign in to comment.