Use string templates to build error message

This commit is contained in:
Daniel García Aubert
2017-09-13 19:27:25 +02:00
parent ee471184b9
commit 4d1a53c20f
+4 -7
View File
@@ -153,24 +153,22 @@ const TYPE = 'aggregation';
*/
function Aggregation(query, options = {}, queries = {}) {
if (typeof options.column !== 'string') {
throw new Error('Aggregation expects `column` in widget options');
throw new Error(`Aggregation expects 'column' in widget options`);
}
if (typeof options.aggregation !== 'string') {
throw new Error('Aggregation expects `aggregation` operation in widget options');
throw new Error(`Aggregation expects 'aggregation' operation in widget options`);
}
if (!VALID_OPERATIONS[options.aggregation]) {
throw new Error("Aggregation does not support '" + options.aggregation + "' operation");
throw new Error(`Aggregation does not support '${options.aggregation}' operation`);
}
var requiredOptions = VALID_OPERATIONS[options.aggregation];
var missingOptions = requiredOptions.filter(requiredOption => !options.hasOwnProperty(requiredOption));
if (missingOptions.length > 0) {
throw new Error(
"Aggregation '" + options.aggregation + "' is missing some options: " + missingOptions.join(',')
);
throw new Error(`Aggregation '${options.aggregation}' is missing some options: ${missingOptions.join(',')}`);
}
BaseWidget.apply(this);
@@ -305,7 +303,6 @@ Aggregation.prototype.format = function(result) {
var maxValue = 0;
var categoriesCount = 0;
if (result.rows.length) {
var firstRow = result.rows[0];
count = firstRow.count;