[errors] fix printing of objects in error data
This commit is contained in:
@ -170,11 +170,7 @@ _.each(statusCodes, function createStatusCodeError(tuple) {
|
|||||||
|
|
||||||
var extraData = _.omit(cause, ['type', 'reason']);
|
var extraData = _.omit(cause, ['type', 'reason']);
|
||||||
if (_.size(extraData)) {
|
if (_.size(extraData)) {
|
||||||
memo += ', with { ' + qs.stringify(extraData, ' ', '=', {
|
memo += ', with ' + prettyPrint(extraData);
|
||||||
encodeURIComponent: function (v) {
|
|
||||||
return String(v).split('\n').join('\\n');
|
|
||||||
}
|
|
||||||
}) + ' }';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return memo;
|
return memo;
|
||||||
@ -194,3 +190,23 @@ _.each(statusCodes, function createStatusCodeError(tuple) {
|
|||||||
errors[name] = StatusCodeError;
|
errors[name] = StatusCodeError;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function prettyPrint(data) {
|
||||||
|
const path = []
|
||||||
|
return (function print(v) {
|
||||||
|
if (typeof v === 'object') {
|
||||||
|
if (path.indexOf(v) > -1) return '[circular]'
|
||||||
|
path.push(v)
|
||||||
|
try {
|
||||||
|
return '{ ' + _.map(v, function (subv, name) {
|
||||||
|
return name + '=' + print(subv)
|
||||||
|
}).join(' & ') + ' }'
|
||||||
|
} finally {
|
||||||
|
path.pop()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return JSON.stringify(v)
|
||||||
|
}
|
||||||
|
}(data))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user