feat(ui): new exception management

pull/188/head
Anthony Lapenna 2016-09-02 17:40:03 +12:00
parent eac3239817
commit 74b97a0036
13 changed files with 59 additions and 109 deletions

View File

@ -34,13 +34,8 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
} }
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();
}, function (e) { }, function (e) {
if (e.status === 404) {
$('.detail').hide();
Messages.error("Not found", "Container not found.");
} else {
Messages.error("Failure", e.data);
}
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();
Messages.error("Failure", e, "Unable to retrieve container info");
}); });
}; };
@ -51,7 +46,7 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
Messages.send("Container started", $stateParams.id); Messages.send("Container started", $stateParams.id);
}, function (e) { }, function (e) {
update(); update();
Messages.error("Failure", "Container failed to start." + e.data); Messages.error("Failure", e, "Unable to start container");
}); });
}; };
@ -62,7 +57,7 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
Messages.send("Container stopped", $stateParams.id); Messages.send("Container stopped", $stateParams.id);
}, function (e) { }, function (e) {
update(); update();
Messages.error("Failure", "Container failed to stop." + e.data); Messages.error("Failure", e, "Unable to stop container");
}); });
}; };
@ -73,7 +68,7 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
Messages.send("Container killed", $stateParams.id); Messages.send("Container killed", $stateParams.id);
}, function (e) { }, function (e) {
update(); update();
Messages.error("Failure", "Container failed to die." + e.data); Messages.error("Failure", e, "Unable to kill container");
}); });
}; };
@ -83,13 +78,13 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
var registry = _.toLower($scope.config.Registry); var registry = _.toLower($scope.config.Registry);
var imageConfig = ImageHelper.createImageConfig(image, registry); var imageConfig = ImageHelper.createImageConfig(image, registry);
ContainerCommit.commit({id: $stateParams.id, tag: imageConfig.tag, repo: imageConfig.repo}, function (d) { ContainerCommit.commit({id: $stateParams.id, tag: imageConfig.tag, repo: imageConfig.repo}, function (d) {
update();
$('#createImageSpinner').hide(); $('#createImageSpinner').hide();
update();
Messages.send("Container commited", $stateParams.id); Messages.send("Container commited", $stateParams.id);
}, function (e) { }, function (e) {
update();
$('#createImageSpinner').hide(); $('#createImageSpinner').hide();
Messages.error("Failure", "Container failed to commit." + e.data); update();
Messages.error("Failure", e, "Unable to commit container");
}); });
}; };
@ -100,7 +95,7 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
Messages.send("Container paused", $stateParams.id); Messages.send("Container paused", $stateParams.id);
}, function (e) { }, function (e) {
update(); update();
Messages.error("Failure", "Container failed to pause." + e.data); Messages.error("Failure", e, "Unable to pause container");
}); });
}; };
@ -111,7 +106,7 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
Messages.send("Container unpaused", $stateParams.id); Messages.send("Container unpaused", $stateParams.id);
}, function (e) { }, function (e) {
update(); update();
Messages.error("Failure", "Container failed to unpause." + e.data); Messages.error("Failure", e, "Unable to unpause container");
}); });
}; };
@ -127,12 +122,8 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
Messages.send("Container removed", $stateParams.id); Messages.send("Container removed", $stateParams.id);
} }
}, function (e) { }, function (e) {
if (e.data.message) {
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to remove container');
}
update(); update();
Messages.error("Failure", e, "Unable to remove container");
}); });
}; };
@ -143,7 +134,7 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
Messages.send("Container restarted", $stateParams.id); Messages.send("Container restarted", $stateParams.id);
}, function (e) { }, function (e) {
update(); update();
Messages.error("Failure", "Container failed to restart." + e.data); Messages.error("Failure", e, "Unable to restart container");
}); });
}; };
@ -151,17 +142,13 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
Container.rename({id: $stateParams.id, 'name': $scope.container.newContainerName}, function (d) { Container.rename({id: $stateParams.id, 'name': $scope.container.newContainerName}, function (d) {
if (d.message) { if (d.message) {
$scope.container.newContainerName = $scope.container.Name; $scope.container.newContainerName = $scope.container.Name;
Messages.error("Unable to rename container", d.message); Messages.error("Unable to rename container", {}, d.message);
} else { } else {
$scope.container.Name = $scope.container.newContainerName; $scope.container.Name = $scope.container.newContainerName;
Messages.send("Container successfully renamed", d.name); Messages.send("Container successfully renamed", d.name);
} }
}, function (e) { }, function (e) {
if (e.data.message) { Messages.error("Failure", e, 'Unable to rename container');
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to rename container');
}
}); });
$scope.container.edit = false; $scope.container.edit = false;
}; };

View File

@ -35,7 +35,7 @@ function ($scope, $stateParams, Settings, Container, Exec, $timeout, Messages) {
Container.exec(execConfig, function(d) { Container.exec(execConfig, function(d) {
if (d.message) { if (d.message) {
$('#loadConsoleSpinner').hide(); $('#loadConsoleSpinner').hide();
Messages.error('Error', d.message); Messages.error("Error", {}, d.message);
} else { } else {
var execId = d.Id; var execId = d.Id;
resizeTTY(execId, termHeight, termWidth); resizeTTY(execId, termHeight, termWidth);
@ -49,11 +49,7 @@ function ($scope, $stateParams, Settings, Container, Exec, $timeout, Messages) {
} }
}, function (e) { }, function (e) {
$('#loadConsoleSpinner').hide(); $('#loadConsoleSpinner').hide();
if (e.data.message) { Messages.error("Failure", e, 'Unable to start an exec instance');
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to start an exec instance');
}
}); });
}; };
@ -71,10 +67,10 @@ function ($scope, $stateParams, Settings, Container, Exec, $timeout, Messages) {
$timeout(function() { $timeout(function() {
Exec.resize({id: execId, height: height, width: width}, function (d) { Exec.resize({id: execId, height: height, width: width}, function (d) {
if (d.message) { if (d.message) {
Messages.error('Error', 'Unable to resize TTY'); Messages.error('Error', {}, 'Unable to resize TTY');
} }
}, function (e) { }, function (e) {
Messages.error("Failure", 'Unable to resize TTY'); Messages.error("Failure", {}, 'Unable to resize TTY');
}); });
}, 2000); }, 2000);

View File

@ -13,12 +13,8 @@ function ($scope, $stateParams, $anchorScroll, ContainerLogs, Container) {
$scope.container = d; $scope.container = d;
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();
}, function (e) { }, function (e) {
if (e.status === 404) {
Messages.error("Not found", "Container not found.");
} else {
Messages.error("Failure", e.data);
}
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();
Messages.error("Failure", e, "Unable to retrieve container info");
}); });
function getLogs() { function getLogs() {

View File

@ -54,7 +54,7 @@ function ($scope, Container, ContainerHelper, Info, Settings, Messages, Config)
Messages.send("Container " + msg, c.Id); Messages.send("Container " + msg, c.Id);
complete(); complete();
}, function (e) { }, function (e) {
Messages.error("Failure", e.data); Messages.error("Failure", e, "Unable to start container");
complete(); complete();
}); });
} }
@ -68,11 +68,7 @@ function ($scope, Container, ContainerHelper, Info, Settings, Messages, Config)
} }
complete(); complete();
}, function (e) { }, function (e) {
if (e.data.message) { Messages.error("Failure", e, 'Unable to remove container');
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to remove container');
}
complete(); complete();
}); });
} }
@ -81,7 +77,7 @@ function ($scope, Container, ContainerHelper, Info, Settings, Messages, Config)
Messages.send("Container " + msg, c.Id); Messages.send("Container " + msg, c.Id);
complete(); complete();
}, function (e) { }, function (e) {
Messages.error("Failure", e.data); Messages.error("Failure", e, 'An error occured');
complete(); complete();
}); });

View File

@ -61,7 +61,7 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages) {
Volume.query({}, function (d) { Volume.query({}, function (d) {
$scope.availableVolumes = d.Volumes; $scope.availableVolumes = d.Volumes;
}, function (e) { }, function (e) {
Messages.error("Failure", e.data); Messages.error("Failure", e, "Unable to retrieve volumes");
}); });
Network.query({}, function (d) { Network.query({}, function (d) {
@ -79,7 +79,7 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages) {
} }
$scope.availableNetworks = networks; $scope.availableNetworks = networks;
}, function (e) { }, function (e) {
Messages.error("Failure", e.data); Messages.error("Failure", e, "Unable to retrieve networks");
}); });
}); });
@ -88,12 +88,12 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages) {
Container.create(config, function (d) { Container.create(config, function (d) {
if (d.message) { if (d.message) {
$('#createContainerSpinner').hide(); $('#createContainerSpinner').hide();
Messages.error('Error', d.message); Messages.error('Error', {}, d.message);
} else { } else {
Container.start({id: d.Id}, {}, function (cd) { Container.start({id: d.Id}, {}, function (cd) {
if (cd.message) { if (cd.message) {
$('#createContainerSpinner').hide(); $('#createContainerSpinner').hide();
Messages.error('Error', cd.message); Messages.error('Error', {}, cd.message);
} else { } else {
$('#createContainerSpinner').hide(); $('#createContainerSpinner').hide();
Messages.send('Container Started', d.Id); Messages.send('Container Started', d.Id);
@ -101,20 +101,12 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages) {
} }
}, function (e) { }, function (e) {
$('#createContainerSpinner').hide(); $('#createContainerSpinner').hide();
if (e.data.message) { Messages.error("Failure", e, 'Unable to start container');
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to start container');
}
}); });
} }
}, function (e) { }, function (e) {
$('#createContainerSpinner').hide(); $('#createContainerSpinner').hide();
if (e.data.message) { Messages.error("Failure", e, 'Unable to create container');
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to create container');
}
}); });
} }
@ -125,13 +117,13 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages) {
if (err) { if (err) {
var detail = data[data.length - 1]; var detail = data[data.length - 1];
$('#createContainerSpinner').hide(); $('#createContainerSpinner').hide();
Messages.error('Error', detail.error); Messages.error('Error', {}, detail.error);
} else { } else {
createContainer(config); createContainer(config);
} }
}, function (e) { }, function (e) {
$('#createContainerSpinner').hide(); $('#createContainerSpinner').hide();
Messages.error('Error', 'Unable to pull image ' + image); Messages.error('Failure', e, 'Unable to pull image');
}); });
} }

View File

@ -29,7 +29,7 @@ function ($scope, $state, Messages, Network) {
Network.create(config, function (d) { Network.create(config, function (d) {
if (d.message) { if (d.message) {
$('#createNetworkSpinner').hide(); $('#createNetworkSpinner').hide();
Messages.error('Unable to create network', d.message); Messages.error('Unable to create network', {}, d.message);
} else { } else {
Messages.send("Network created", d.Id); Messages.send("Network created", d.Id);
$('#createNetworkSpinner').hide(); $('#createNetworkSpinner').hide();
@ -37,11 +37,7 @@ function ($scope, $state, Messages, Network) {
} }
}, function (e) { }, function (e) {
$('#createNetworkSpinner').hide(); $('#createNetworkSpinner').hide();
if (e.data.message) { Messages.error("Failure", e, 'Unable to create network');
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to create network');
}
}); });
} }

View File

@ -23,7 +23,7 @@ function ($scope, $state, Volume, Messages) {
Volume.create(config, function (d) { Volume.create(config, function (d) {
if (d.message) { if (d.message) {
$('#createVolumeSpinner').hide(); $('#createVolumeSpinner').hide();
Messages.error('Unable to create volume', d.message); Messages.error('Unable to create volume', {}, d.message);
} else { } else {
Messages.send("Volume created", d.Name); Messages.send("Volume created", d.Name);
$('#createVolumeSpinner').hide(); $('#createVolumeSpinner').hide();
@ -31,11 +31,7 @@ function ($scope, $state, Volume, Messages) {
} }
}, function (e) { }, function (e) {
$('#createVolumeSpinner').hide(); $('#createVolumeSpinner').hide();
if (e.data.message) { Messages.error("Failure", e, 'Unable to create volume');
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to create volume');
}
}); });
} }

View File

@ -21,7 +21,7 @@ function ($scope, Settings, Messages, Events) {
$('#loadEventsSpinner').hide(); $('#loadEventsSpinner').hide();
}, },
function (e) { function (e) {
Messages.error("Unable to load events", e.data);
$('#loadEventsSpinner').hide(); $('#loadEventsSpinner').hide();
Messages.error("Failure", e, "Unable to load events");
}); });
}]); }]);

View File

@ -30,7 +30,7 @@ function ($scope, $stateParams, $state, Image, ImageHelper, Messages) {
$state.go('image', {id: $stateParams.id}, {reload: true}); $state.go('image', {id: $stateParams.id}, {reload: true});
}, function(e) { }, function(e) {
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();
Messages.error("Unable to tag image", e.data); Messages.error("Failure", e, "Unable to tag image");
}); });
}; };
@ -38,14 +38,14 @@ function ($scope, $stateParams, $state, Image, ImageHelper, Messages) {
$('#loadingViewSpinner').show(); $('#loadingViewSpinner').show();
Image.push({tag: tag}, function (d) { Image.push({tag: tag}, function (d) {
if (d[d.length-1].error) { if (d[d.length-1].error) {
Messages.error("Unable to push image", d[d.length-1].error); Messages.error("Unable to push image", {}, d[d.length-1].error);
} else { } else {
Messages.send('Image successfully pushed'); Messages.send('Image successfully pushed');
} }
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();
}, function (e) { }, function (e) {
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();
Messages.error("Unable to push image", e.data); Messages.error("Failure", e, "Unable to push image");
}); });
}; };
@ -54,7 +54,7 @@ function ($scope, $stateParams, $state, Image, ImageHelper, Messages) {
Image.remove({id: id}, function (d) { Image.remove({id: id}, function (d) {
if (d[0].message) { if (d[0].message) {
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();
Messages.error("Unable to remove image", d[0].message); Messages.error("Unable to remove image", {}, d[0].message);
} else { } else {
// If last message key is 'Deleted' or if it's 'Untagged' and there is only one tag associated to the image // If last message key is 'Deleted' or if it's 'Untagged' and there is only one tag associated to the image
// then assume the image is gone and send to images page // then assume the image is gone and send to images page
@ -68,11 +68,7 @@ function ($scope, $stateParams, $state, Image, ImageHelper, Messages) {
} }
}, function (e) { }, function (e) {
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();
if (e.data.message) { Messages.error("Failure", e, 'Unable to remove image');
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to remove image');
}
}); });
}; };
@ -88,10 +84,6 @@ function ($scope, $stateParams, $state, Image, ImageHelper, Messages) {
$scope.exposedPorts = d.ContainerConfig.ExposedPorts ? Object.keys(d.ContainerConfig.ExposedPorts) : []; $scope.exposedPorts = d.ContainerConfig.ExposedPorts ? Object.keys(d.ContainerConfig.ExposedPorts) : [];
$scope.volumes = d.ContainerConfig.Volumes ? Object.keys(d.ContainerConfig.Volumes) : []; $scope.volumes = d.ContainerConfig.Volumes ? Object.keys(d.ContainerConfig.Volumes) : [];
}, function (e) { }, function (e) {
if (e.status === 404) { Messages.error("Failure", e, "Unable to retrieve image info");
Messages.error("Unable to find image", $stateParams.id);
} else {
Messages.error("Unable to retrieve image info", e.data);
}
}); });
}]); }]);

View File

@ -47,14 +47,14 @@ function ($scope, $state, Config, Image, Messages) {
if (err) { if (err) {
var detail = data[data.length - 1]; var detail = data[data.length - 1];
$('#pullImageSpinner').hide(); $('#pullImageSpinner').hide();
Messages.error('Error', detail.error); Messages.error('Error', {}, detail.error);
} else { } else {
$('#pullImageSpinner').hide(); $('#pullImageSpinner').hide();
$state.go('images', {}, {reload: true}); $state.go('images', {}, {reload: true});
} }
}, function (e) { }, function (e) {
$('#pullImageSpinner').hide(); $('#pullImageSpinner').hide();
Messages.error('Error', 'Unable to pull image ' + image); Messages.error("Failure", e, "Unable to pull image");
}); });
}; };
@ -73,7 +73,7 @@ function ($scope, $state, Config, Image, Messages) {
Image.remove({id: i.Id}, function (d) { Image.remove({id: i.Id}, function (d) {
if (d[0].message) { if (d[0].message) {
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();
Messages.error("Unable to remove image", d[0].message); Messages.error("Unable to remove image", {}, d[0].message);
} else { } else {
Messages.send("Image deleted", i.Id); Messages.send("Image deleted", i.Id);
var index = $scope.images.indexOf(i); var index = $scope.images.indexOf(i);
@ -81,11 +81,7 @@ function ($scope, $state, Config, Image, Messages) {
} }
complete(); complete();
}, function (e) { }, function (e) {
if (e.data.message) { Messages.error("Failure", e, 'Unable to remove image');
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to remove image');
}
complete(); complete();
}); });
} }
@ -99,8 +95,8 @@ function ($scope, $state, Config, Image, Messages) {
}); });
$('#loadImagesSpinner').hide(); $('#loadImagesSpinner').hide();
}, function (e) { }, function (e) {
Messages.error("Failure", e.data);
$('#loadImagesSpinner').hide(); $('#loadImagesSpinner').hide();
Messages.error("Failure", e, "Unable to retrieve images");
}); });
} }

View File

@ -54,11 +54,7 @@ function ($scope, $state, Network, Config, Messages) {
} }
complete(); complete();
}, function (e) { }, function (e) {
if (e.data.message) { Messages.error("Failure", e, 'Unable to remove network');
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to remove network');
}
complete(); complete();
}); });
} }
@ -71,8 +67,8 @@ function ($scope, $state, Network, Config, Messages) {
$scope.networks = d; $scope.networks = d;
$('#loadNetworksSpinner').hide(); $('#loadNetworksSpinner').hide();
}, function (e) { }, function (e) {
Messages.error("Failure", e.data);
$('#loadNetworksSpinner').hide(); $('#loadNetworksSpinner').hide();
Messages.error("Failure", e, "Unable to retrieve networks");
}); });
} }

View File

@ -112,7 +112,7 @@ function (Settings, $scope, Messages, $timeout, Container, ContainerTop, $stateP
return d[key]; return d[key];
}); });
if (arr.join('').indexOf('no such id') !== -1) { if (arr.join('').indexOf('no such id') !== -1) {
Messages.error('Unable to retrieve stats', 'Is this container running?'); Messages.error('Unable to retrieve stats', {}, 'Is this container running?');
return; return;
} }
@ -123,7 +123,7 @@ function (Settings, $scope, Messages, $timeout, Container, ContainerTop, $stateP
updateNetworkChart(d); updateNetworkChart(d);
timeout = $timeout(updateStats, 5000); timeout = $timeout(updateStats, 5000);
}, function () { }, function () {
Messages.error('Unable to retrieve stats', 'Is this container running?'); Messages.error('Unable to retrieve stats', {}, 'Is this container running?');
timeout = $timeout(updateStats, 5000); timeout = $timeout(updateStats, 5000);
}); });
} }
@ -188,7 +188,7 @@ function (Settings, $scope, Messages, $timeout, Container, ContainerTop, $stateP
Container.get({id: $stateParams.id}, function (d) { Container.get({id: $stateParams.id}, function (d) {
$scope.container = d; $scope.container = d;
}, function (e) { }, function (e) {
Messages.error("Failure", e.data); Messages.error("Failure", e, "Unable to retrieve container info");
}); });
$scope.getTop(); $scope.getTop();
}]); }]);

View File

@ -206,10 +206,17 @@ angular.module('uifordocker.services', ['ngResource', 'ngSanitize'])
} }
}); });
}, },
error: function (title, text) { error: function (title, e, fallbackText) {
console.log(JSON.stringify(e, null, 4));
var msg = fallbackText;
if (e.data && e.data.message) {
msg = e.data.message;
} else if (e.message) {
msg = e.message;
}
$.gritter.add({ $.gritter.add({
title: $sanitize(title), title: $sanitize(title),
text: $sanitize(text), text: $sanitize(msg),
time: 10000, time: 10000,
before_open: function () { before_open: function () {
if ($('.gritter-item-wrapper').length === 4) { if ($('.gritter-item-wrapper').length === 4) {