throw errors for multiple defaults

This commit is contained in:
Ryan Vazquez
2020-10-16 10:30:48 -04:00
parent d47e2287b5
commit a508287b9c
+5 -11
View File
@@ -17,16 +17,10 @@
import { Metric } from '../types';
export function validateMetrics(metrics: Metric[]) {
let defaultMetric = null;
for (const metric of metrics) {
if (metric.default) {
if (defaultMetric) {
throw new Error(
`Cannot set default for multiple metrics: Received: ${defaultMetric.kind} and ${metric.kind}`,
);
} else {
defaultMetric = metric;
}
}
const defaults = metrics.filter(metric => metric.default);
if (defaults.length > 1) {
throw new Error(
`Only one default metric can be set at a time. Found ${defaults.length}`,
);
}
}