[errors] tweak error messages to be more human readable

From: [index_not_found_exception] no such index, with: {"resource.type":"index_or_alias","resource.id":"logstash-2015.09.01","index":"logstash-2015.09.01"}
To: [index_not_found_exception] no such index, with { resource.type=index_or_alias resource.id=logstash-2015.09.01 index=logstash-2015.09.01 }
This commit is contained in:
spalger
2015-09-25 15:36:36 -07:00
parent adf4654374
commit 6a789754ea

View File

@ -1,4 +1,5 @@
var _ = require('./utils');
var qs = require('querystring');
var errors = module.exports;
var canCapture = (typeof Error.captureStackTrace === 'function');
@ -164,7 +165,11 @@ _.each(statusCodes, function (name, status) {
var extraData = _.omit(cause, ['type', 'reason']);
if (_.size(extraData)) {
memo += ', with: ' + JSON.stringify(extraData);
memo += ', with { ' + qs.stringify(extraData, ' ', '=', {
encodeURIComponent: function (v) {
return String(v).split('\n').join('\\n');
}
}) + ' }';
}
return memo;
@ -182,4 +187,4 @@ _.each(statusCodes, function (name, status) {
_.inherits(StatusCodeError, ErrorAbstract);
errors[className] = StatusCodeError;
errors[status] = StatusCodeError;
});
});