Skip to content

Commit 0366a0d

Browse files
Merge pull request #354 from zendesk/minor-fix-messages
fix: dedicated 404 error handling and improved error messages for connectors delete command
2 parents 8d94108 + 103fb63 commit 0366a0d

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

packages/zcli-connectors/src/commands/connectors/delete.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ export default class Delete extends Command {
8585
// Handle response
8686
if (response.status === 200 || response.status === 204) {
8787
this.log(chalk.green(`✓ Connector '${connectorName}' deleted successfully`))
88+
} else if (response.status === 404) {
89+
const errorMessage = `Connector '${connectorName}' not found. It may have already been deleted or does not exist.`
90+
if (flags.verbose) {
91+
this.logVerbose('\nError Details:', 'red')
92+
this.logVerbose(errorMessage, 'red')
93+
}
94+
this.error(errorMessage, { exit: 1 })
8895
} else {
8996
// Handle error response
9097
spinner?.stop()

packages/zcli-connectors/tests/functional/delete.test.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ describe('delete command', () => {
320320
})
321321
})
322322

323-
it('should handle 404 Not Found response', async () => {
323+
it('should handle 404 Not Found response with specific not-found message', async () => {
324324
requestAPIStub.resolves({
325325
status: 404,
326326
data: { error: 'Not Found' }
@@ -335,11 +335,38 @@ describe('delete command', () => {
335335

336336
sinon.assert.calledWith(
337337
errorStub,
338-
sinon.match(/Failed to delete connector: HTTP 404/),
338+
sinon.match(/Connector 'test-connector' not found\. It may have already been deleted or does not exist\./),
339339
sinon.match({ exit: 1 })
340340
)
341341
})
342342

343+
it('should log verbose error details on 404 when verbose flag is set', async () => {
344+
parseStub.restore()
345+
parseStub = sinon.stub(deleteCommand, 'parse' as any).resolves({
346+
args: { connector: 'test-connector' },
347+
flags: {
348+
verbose: true,
349+
force: true,
350+
help: false
351+
}
352+
})
353+
354+
requestAPIStub.resolves({
355+
status: 404,
356+
data: { error: 'Not Found' }
357+
})
358+
359+
try {
360+
await deleteCommand.run()
361+
expect.fail('Should have thrown an error')
362+
} catch (error) {
363+
// Expected
364+
}
365+
366+
sinon.assert.calledWith(logStub, sinon.match(/Error Details:/))
367+
sinon.assert.calledWith(logStub, sinon.match(/not found/))
368+
})
369+
343370
it('should handle 403 Forbidden response', async () => {
344371
requestAPIStub.resolves({
345372
status: 403,

0 commit comments

Comments
 (0)