Pārlūkot izejas kodu

Dashboard: show error when importing dashboard json file with broken/incorrect json syntax, Closes #878

Torkel Ödegaard 11 gadi atpakaļ
vecāks
revīzija
1c7b898b01

+ 7 - 1
src/app/directives/dashUpload.js

@@ -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);
               });

+ 4 - 4
src/app/routes/dashboard-from-db.js

@@ -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;
     }