Skip to content

Commit ae08a07

Browse files
authored
fix: Outputting entire error response w/ JSON format flag enabled (twilio#111)
1 parent 70291f0 commit ae08a07

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/base-commands/base-command.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class BaseCommand extends Command {
6363
if (instanceOf(error, TwilioCliError)) {
6464
// User/API errors
6565
if (this.flags['cli-output-format'] === 'json') {
66-
this.output(error);
66+
this.output(error.data);
6767
} else {
6868
this.logger.error(error.message);
6969
this.logger.debug(error.stack);

src/services/cli-http-client.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class CliRequestClient {
9494
this.logger.debug(`response.headers: ${JSON.stringify(response.headers)}`);
9595

9696
if (response.status < 200 || response.status >= 400) {
97-
const { message, code, details } = this.formatErrorMessage(response.data);
98-
throw new TwilioCliError(message, code, details);
97+
const { message, code } = this.formatErrorMessage(response.data);
98+
throw new TwilioCliError(message, code, response.data);
9999
}
100100

101101
return {

src/services/error.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class TwilioCliError extends Error {
2-
constructor(message, exitCode, details = 'No details provided') {
2+
constructor(message, exitCode, data) {
33
super(message);
44
this.name = this.constructor.name;
55
this.exitCode = exitCode;
6-
this.details = details;
6+
this.data = data;
77
}
88
}
99

test/base-commands/base-command.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('base-commands', () => {
6868
await ctx.testCmd.catch(new TwilioCliError('oh no', 1, { errors: [{ message: 'oh no' }] }));
6969
})
7070
.exit(1)
71-
.it('can correctly display error details', (ctx) => {
71+
.it('can correctly display error data', (ctx) => {
7272
expect(ctx.stdout).to.contain(`"message": "oh no"`);
7373
});
7474

0 commit comments

Comments
 (0)