From 0c977b75f194772ca804405e2dd049210837adb8 Mon Sep 17 00:00:00 2001 From: rozetko Date: Fri, 9 Nov 2018 15:12:45 +0000 Subject: [PATCH] Proper error on creating analytic unit with multiple metrics --- src/models/metric.ts | 5 ++++- src/module.ts | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/models/metric.ts b/src/models/metric.ts index 7d3b250..b260db6 100644 --- a/src/models/metric.ts +++ b/src/models/metric.ts @@ -37,6 +37,9 @@ export class Metric { export class MetricExpanded { private _targets: Target[]; constructor(public datasource: string, targets: any[]) { + if(targets.length > 1) { + throw new Error('Multiple metrics are not supported currently'); + } this._targets = targets.map(t => new Target(t)); } @@ -55,4 +58,4 @@ export class MetricMap { this._cache.set(t.getHash(), t); }); } -} \ No newline at end of file +} diff --git a/src/module.ts b/src/module.ts index ec87799..c4afc24 100644 --- a/src/module.ts +++ b/src/module.ts @@ -532,11 +532,19 @@ class GraphCtrl extends MetricsPanelCtrl { async saveNew() { this.refresh(); - await this.analyticsController.saveNew( - new MetricExpanded(this.panel.datasource, this.panel.targets), - this.datasourceRequest, - this.panel.id - ); + try { + await this.analyticsController.saveNew( + new MetricExpanded(this.panel.datasource, this.panel.targets), + this.datasourceRequest, + this.panel.id + ); + } catch(e) { + this.alertSrv.set( + 'Error while saving analytic unit', + e.message, + 'error', 7000 + ); + } this.$scope.$digest(); this.render(this.seriesList); }