node-triton#90 triton
CLI should summarize err.body.errors
from CloudAPI
This commit is contained in:
parent
7f24f0235a
commit
70c7bbd434
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
## 4.5.1 (not yet released)
|
## 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
|
## 4.5.0
|
||||||
|
21
lib/cli.js
21
lib/cli.js
@ -400,11 +400,28 @@ function main(argv) {
|
|||||||
if (code === 'NoCommand') {
|
if (code === 'NoCommand') {
|
||||||
/* jsl:pass */
|
/* jsl:pass */
|
||||||
} else if (err.message !== undefined) {
|
} 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,
|
cli.name,
|
||||||
(subcmd ? ' ' + subcmd : ''),
|
(subcmd ? ' ' + subcmd : ''),
|
||||||
(code ? format(' (%s)', code) : ''),
|
(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 this is a usage error, attempt to show some usage info.
|
||||||
if (['Usage', 'Option'].indexOf(code) !== -1 && subcmd) {
|
if (['Usage', 'Option'].indexOf(code) !== -1 && subcmd) {
|
||||||
|
Reference in New Issue
Block a user