Commit 1c7b898b by Torkel Ödegaard

Dashboard: show error when importing dashboard json file with broken/incorrect…

Dashboard: show error when importing dashboard json file with broken/incorrect json syntax, Closes #878
parent 7ad18da0
......@@ -16,7 +16,13 @@ function (angular, kbn) {
var readerOnload = function() {
return function(e) {
scope.$apply(function() {
window.grafanaImportDashboard = JSON.parse(e.target.result);
try {
window.grafanaImportDashboard = JSON.parse(e.target.result);
} catch (err) {
console.log(err);
scope.appEvent('alert-error', ['Import failed', 'JSON -> JS Serialization failed: ' + err.message]);
return;
}
var title = kbn.slugifyForUrl(window.grafanaImportDashboard.title);
$location.path('/dashboard/import/' + title);
});
......
......@@ -31,7 +31,7 @@ function (angular) {
});
module.controller('DashFromDBProvider', function($scope, $rootScope, datasourceSrv, $routeParams, alertSrv) {
module.controller('DashFromDBProvider', function($scope, $rootScope, datasourceSrv, $routeParams) {
var db = datasourceSrv.getGrafanaDB();
var isTemp = window.location.href.indexOf('dashboard/temp') !== -1;
......@@ -41,14 +41,14 @@ function (angular) {
$scope.initDashboard(dashboard, $scope);
}).then(null, function(error) {
$scope.initDashboard({ title: 'Grafana'}, $scope);
alertSrv.set('Error', error, 'error');
$scope.appEvent('alert-error', ['Dashboard load failed', error]);
});
});
module.controller('DashFromImportCtrl', function($scope, $location, alertSrv) {
module.controller('DashFromImportCtrl', function($scope, $location) {
if (!window.grafanaImportDashboard) {
alertSrv.set('Not found', 'Cannot reload page with unsaved imported dashboard', 'warning', 7000);
$scope.appEvent('alert-warning', ['Dashboard load failed', 'Cannot reload unsaved imported dashboard']);
$location.path('');
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment