Skip to content

Commit

Permalink
fix: Outputting entire error response w/ JSON format flag enabled (tw…
Browse files Browse the repository at this point in the history
  • Loading branch information
alecnicolas committed Jan 22, 2021
1 parent 70291f0 commit ae08a07
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/base-commands/base-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class BaseCommand extends Command {
if (instanceOf(error, TwilioCliError)) {
// User/API errors
if (this.flags['cli-output-format'] === 'json') {
this.output(error);
this.output(error.data);
} else {
this.logger.error(error.message);
this.logger.debug(error.stack);
Expand Down
4 changes: 2 additions & 2 deletions src/services/cli-http-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class CliRequestClient {
this.logger.debug(`response.headers: ${JSON.stringify(response.headers)}`);

if (response.status < 200 || response.status >= 400) {
const { message, code, details } = this.formatErrorMessage(response.data);
throw new TwilioCliError(message, code, details);
const { message, code } = this.formatErrorMessage(response.data);
throw new TwilioCliError(message, code, response.data);
}

return {
Expand Down
4 changes: 2 additions & 2 deletions src/services/error.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class TwilioCliError extends Error {
constructor(message, exitCode, details = 'No details provided') {
constructor(message, exitCode, data) {
super(message);
this.name = this.constructor.name;
this.exitCode = exitCode;
this.details = details;
this.data = data;
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/base-commands/base-command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('base-commands', () => {
await ctx.testCmd.catch(new TwilioCliError('oh no', 1, { errors: [{ message: 'oh no' }] }));
})
.exit(1)
.it('can correctly display error details', (ctx) => {
.it('can correctly display error data', (ctx) => {
expect(ctx.stdout).to.contain(`"message": "oh no"`);
});

Expand Down

0 comments on commit ae08a07

Please sign in to comment.