node-triton#90 triton CLI should summarize err.body.errors from CloudAPI

This commit is contained in:
Trent Mick 2016-02-12 11:09:55 -08:00
parent 7f24f0235a
commit 70c7bbd434
2 changed files with 22 additions and 3 deletions

View File

@ -2,7 +2,9 @@
## 4.5.1 (not yet released)
(nothing yet)
- #92 `triton` CLI should summarize `err.body.errors` from CloudAPI
Per <https://github.com/joyent/eng/blob/master/docs/index.md#error-handling>,
CloudAPI error response will sometimes have extra error details to show.
## 4.5.0

View File

@ -400,11 +400,28 @@ function main(argv) {
if (code === 'NoCommand') {
/* jsl:pass */
} else if (err.message !== undefined) {
console.error('%s%s: error%s: %s',
/*
* If the err has `body.errors` (as some Triton/SDC APIs do per
* // JSSTYLED
* https://github.com/joyent/eng/blob/master/docs/index.md#error-handling
* then append a one-line summary for each error object.
*/
var bodyErrors = '';
if (err.body && err.body.errors) {
err.body.errors.forEach(function (e) {
bodyErrors += format('\n %s: %s', e.field, e.code);
if (e.message) {
bodyErrors += ': ' + e.message;
}
});
}
console.error('%s%s: error%s: %s%s',
cli.name,
(subcmd ? ' ' + subcmd : ''),
(code ? format(' (%s)', code) : ''),
(cli.showErrStack ? err.stack : err.message));
(cli.showErrStack ? err.stack : err.message),
bodyErrors);
// If this is a usage error, attempt to show some usage info.
if (['Usage', 'Option'].indexOf(code) !== -1 && subcmd) {