diff --git a/app/components/container/containerController.js b/app/components/container/containerController.js index 98f614d61..94a23a05d 100644 --- a/app/components/container/containerController.js +++ b/app/components/container/containerController.js @@ -34,13 +34,8 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima } $('#loadingViewSpinner').hide(); }, function (e) { - if (e.status === 404) { - $('.detail').hide(); - Messages.error("Not found", "Container not found."); - } else { - Messages.error("Failure", e.data); - } $('#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); }, function (e) { 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); }, function (e) { 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); }, function (e) { 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 imageConfig = ImageHelper.createImageConfig(image, registry); ContainerCommit.commit({id: $stateParams.id, tag: imageConfig.tag, repo: imageConfig.repo}, function (d) { - update(); $('#createImageSpinner').hide(); + update(); Messages.send("Container commited", $stateParams.id); }, function (e) { - update(); $('#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); }, function (e) { 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); }, function (e) { 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); } }, function (e) { - if (e.data.message) { - Messages.error("Failure", e.data.message); - } else { - Messages.error("Failure", 'Unable to remove container'); - } 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); }, function (e) { 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) { if (d.message) { $scope.container.newContainerName = $scope.container.Name; - Messages.error("Unable to rename container", d.message); + Messages.error("Unable to rename container", {}, d.message); } else { $scope.container.Name = $scope.container.newContainerName; Messages.send("Container successfully renamed", d.name); } }, function (e) { - if (e.data.message) { - Messages.error("Failure", e.data.message); - } else { - Messages.error("Failure", 'Unable to rename container'); - } + Messages.error("Failure", e, 'Unable to rename container'); }); $scope.container.edit = false; }; diff --git a/app/components/containerConsole/containerConsoleController.js b/app/components/containerConsole/containerConsoleController.js index 2fdfd67b6..7bcd91734 100644 --- a/app/components/containerConsole/containerConsoleController.js +++ b/app/components/containerConsole/containerConsoleController.js @@ -35,7 +35,7 @@ function ($scope, $stateParams, Settings, Container, Exec, $timeout, Messages) { Container.exec(execConfig, function(d) { if (d.message) { $('#loadConsoleSpinner').hide(); - Messages.error('Error', d.message); + Messages.error("Error", {}, d.message); } else { var execId = d.Id; resizeTTY(execId, termHeight, termWidth); @@ -49,11 +49,7 @@ function ($scope, $stateParams, Settings, Container, Exec, $timeout, Messages) { } }, function (e) { $('#loadConsoleSpinner').hide(); - if (e.data.message) { - Messages.error("Failure", e.data.message); - } else { - Messages.error("Failure", 'Unable to start an exec instance'); - } + Messages.error("Failure", e, 'Unable to start an exec instance'); }); }; @@ -71,10 +67,10 @@ function ($scope, $stateParams, Settings, Container, Exec, $timeout, Messages) { $timeout(function() { Exec.resize({id: execId, height: height, width: width}, function (d) { if (d.message) { - Messages.error('Error', 'Unable to resize TTY'); + Messages.error('Error', {}, 'Unable to resize TTY'); } }, function (e) { - Messages.error("Failure", 'Unable to resize TTY'); + Messages.error("Failure", {}, 'Unable to resize TTY'); }); }, 2000); diff --git a/app/components/containerLogs/containerLogsController.js b/app/components/containerLogs/containerLogsController.js index 56273ee0c..fbba46058 100644 --- a/app/components/containerLogs/containerLogsController.js +++ b/app/components/containerLogs/containerLogsController.js @@ -13,12 +13,8 @@ function ($scope, $stateParams, $anchorScroll, ContainerLogs, Container) { $scope.container = d; $('#loadingViewSpinner').hide(); }, function (e) { - if (e.status === 404) { - Messages.error("Not found", "Container not found."); - } else { - Messages.error("Failure", e.data); - } $('#loadingViewSpinner').hide(); + Messages.error("Failure", e, "Unable to retrieve container info"); }); function getLogs() { diff --git a/app/components/containers/containersController.js b/app/components/containers/containersController.js index d399a9e55..db2898001 100644 --- a/app/components/containers/containersController.js +++ b/app/components/containers/containersController.js @@ -54,7 +54,7 @@ function ($scope, Container, ContainerHelper, Info, Settings, Messages, Config) Messages.send("Container " + msg, c.Id); complete(); }, function (e) { - Messages.error("Failure", e.data); + Messages.error("Failure", e, "Unable to start container"); complete(); }); } @@ -68,11 +68,7 @@ function ($scope, Container, ContainerHelper, Info, Settings, Messages, Config) } complete(); }, function (e) { - if (e.data.message) { - Messages.error("Failure", e.data.message); - } else { - Messages.error("Failure", 'Unable to remove container'); - } + Messages.error("Failure", e, 'Unable to remove container'); complete(); }); } @@ -81,7 +77,7 @@ function ($scope, Container, ContainerHelper, Info, Settings, Messages, Config) Messages.send("Container " + msg, c.Id); complete(); }, function (e) { - Messages.error("Failure", e.data); + Messages.error("Failure", e, 'An error occured'); complete(); }); diff --git a/app/components/createContainer/createContainerController.js b/app/components/createContainer/createContainerController.js index e16987228..4724c4111 100644 --- a/app/components/createContainer/createContainerController.js +++ b/app/components/createContainer/createContainerController.js @@ -61,7 +61,7 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages) { Volume.query({}, function (d) { $scope.availableVolumes = d.Volumes; }, function (e) { - Messages.error("Failure", e.data); + Messages.error("Failure", e, "Unable to retrieve volumes"); }); Network.query({}, function (d) { @@ -79,7 +79,7 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages) { } $scope.availableNetworks = networks; }, 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) { if (d.message) { $('#createContainerSpinner').hide(); - Messages.error('Error', d.message); + Messages.error('Error', {}, d.message); } else { Container.start({id: d.Id}, {}, function (cd) { if (cd.message) { $('#createContainerSpinner').hide(); - Messages.error('Error', cd.message); + Messages.error('Error', {}, cd.message); } else { $('#createContainerSpinner').hide(); Messages.send('Container Started', d.Id); @@ -101,20 +101,12 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages) { } }, function (e) { $('#createContainerSpinner').hide(); - if (e.data.message) { - Messages.error("Failure", e.data.message); - } else { - Messages.error("Failure", 'Unable to start container'); - } + Messages.error("Failure", e, 'Unable to start container'); }); } }, function (e) { $('#createContainerSpinner').hide(); - if (e.data.message) { - Messages.error("Failure", e.data.message); - } else { - Messages.error("Failure", 'Unable to create container'); - } + Messages.error("Failure", e, 'Unable to create container'); }); } @@ -125,13 +117,13 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages) { if (err) { var detail = data[data.length - 1]; $('#createContainerSpinner').hide(); - Messages.error('Error', detail.error); + Messages.error('Error', {}, detail.error); } else { createContainer(config); } }, function (e) { $('#createContainerSpinner').hide(); - Messages.error('Error', 'Unable to pull image ' + image); + Messages.error('Failure', e, 'Unable to pull image'); }); } diff --git a/app/components/createNetwork/createNetworkController.js b/app/components/createNetwork/createNetworkController.js index 2eb35f913..cb99db101 100644 --- a/app/components/createNetwork/createNetworkController.js +++ b/app/components/createNetwork/createNetworkController.js @@ -29,7 +29,7 @@ function ($scope, $state, Messages, Network) { Network.create(config, function (d) { if (d.message) { $('#createNetworkSpinner').hide(); - Messages.error('Unable to create network', d.message); + Messages.error('Unable to create network', {}, d.message); } else { Messages.send("Network created", d.Id); $('#createNetworkSpinner').hide(); @@ -37,11 +37,7 @@ function ($scope, $state, Messages, Network) { } }, function (e) { $('#createNetworkSpinner').hide(); - if (e.data.message) { - Messages.error("Failure", e.data.message); - } else { - Messages.error("Failure", 'Unable to create network'); - } + Messages.error("Failure", e, 'Unable to create network'); }); } diff --git a/app/components/createVolume/createVolumeController.js b/app/components/createVolume/createVolumeController.js index 1e65ad287..def0b5dcc 100644 --- a/app/components/createVolume/createVolumeController.js +++ b/app/components/createVolume/createVolumeController.js @@ -23,7 +23,7 @@ function ($scope, $state, Volume, Messages) { Volume.create(config, function (d) { if (d.message) { $('#createVolumeSpinner').hide(); - Messages.error('Unable to create volume', d.message); + Messages.error('Unable to create volume', {}, d.message); } else { Messages.send("Volume created", d.Name); $('#createVolumeSpinner').hide(); @@ -31,11 +31,7 @@ function ($scope, $state, Volume, Messages) { } }, function (e) { $('#createVolumeSpinner').hide(); - if (e.data.message) { - Messages.error("Failure", e.data.message); - } else { - Messages.error("Failure", 'Unable to create volume'); - } + Messages.error("Failure", e, 'Unable to create volume'); }); } diff --git a/app/components/events/eventsController.js b/app/components/events/eventsController.js index 8450bdb71..3ee19e4de 100644 --- a/app/components/events/eventsController.js +++ b/app/components/events/eventsController.js @@ -21,7 +21,7 @@ function ($scope, Settings, Messages, Events) { $('#loadEventsSpinner').hide(); }, function (e) { - Messages.error("Unable to load events", e.data); $('#loadEventsSpinner').hide(); + Messages.error("Failure", e, "Unable to load events"); }); }]); diff --git a/app/components/image/imageController.js b/app/components/image/imageController.js index a0eac1bc8..8ad61a242 100644 --- a/app/components/image/imageController.js +++ b/app/components/image/imageController.js @@ -30,7 +30,7 @@ function ($scope, $stateParams, $state, Image, ImageHelper, Messages) { $state.go('image', {id: $stateParams.id}, {reload: true}); }, function(e) { $('#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(); Image.push({tag: tag}, function (d) { 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 { Messages.send('Image successfully pushed'); } $('#loadingViewSpinner').hide(); }, function (e) { $('#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) { if (d[0].message) { $('#loadingViewSpinner').hide(); - Messages.error("Unable to remove image", d[0].message); + Messages.error("Unable to remove image", {}, d[0].message); } else { // 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 @@ -68,11 +68,7 @@ function ($scope, $stateParams, $state, Image, ImageHelper, Messages) { } }, function (e) { $('#loadingViewSpinner').hide(); - if (e.data.message) { - Messages.error("Failure", e.data.message); - } else { - Messages.error("Failure", 'Unable to remove image'); - } + Messages.error("Failure", e, '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.volumes = d.ContainerConfig.Volumes ? Object.keys(d.ContainerConfig.Volumes) : []; }, function (e) { - if (e.status === 404) { - Messages.error("Unable to find image", $stateParams.id); - } else { - Messages.error("Unable to retrieve image info", e.data); - } + Messages.error("Failure", e, "Unable to retrieve image info"); }); }]); diff --git a/app/components/images/imagesController.js b/app/components/images/imagesController.js index a33c5b523..2d692c707 100644 --- a/app/components/images/imagesController.js +++ b/app/components/images/imagesController.js @@ -47,14 +47,14 @@ function ($scope, $state, Config, Image, Messages) { if (err) { var detail = data[data.length - 1]; $('#pullImageSpinner').hide(); - Messages.error('Error', detail.error); + Messages.error('Error', {}, detail.error); } else { $('#pullImageSpinner').hide(); $state.go('images', {}, {reload: true}); } }, function (e) { $('#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) { if (d[0].message) { $('#loadingViewSpinner').hide(); - Messages.error("Unable to remove image", d[0].message); + Messages.error("Unable to remove image", {}, d[0].message); } else { Messages.send("Image deleted", i.Id); var index = $scope.images.indexOf(i); @@ -81,11 +81,7 @@ function ($scope, $state, Config, Image, Messages) { } complete(); }, function (e) { - if (e.data.message) { - Messages.error("Failure", e.data.message); - } else { - Messages.error("Failure", 'Unable to remove image'); - } + Messages.error("Failure", e, 'Unable to remove image'); complete(); }); } @@ -99,8 +95,8 @@ function ($scope, $state, Config, Image, Messages) { }); $('#loadImagesSpinner').hide(); }, function (e) { - Messages.error("Failure", e.data); $('#loadImagesSpinner').hide(); + Messages.error("Failure", e, "Unable to retrieve images"); }); } diff --git a/app/components/networks/networksController.js b/app/components/networks/networksController.js index a2b5dcd61..8a5287286 100644 --- a/app/components/networks/networksController.js +++ b/app/components/networks/networksController.js @@ -54,11 +54,7 @@ function ($scope, $state, Network, Config, Messages) { } complete(); }, function (e) { - if (e.data.message) { - Messages.error("Failure", e.data.message); - } else { - Messages.error("Failure", 'Unable to remove network'); - } + Messages.error("Failure", e, 'Unable to remove network'); complete(); }); } @@ -71,8 +67,8 @@ function ($scope, $state, Network, Config, Messages) { $scope.networks = d; $('#loadNetworksSpinner').hide(); }, function (e) { - Messages.error("Failure", e.data); $('#loadNetworksSpinner').hide(); + Messages.error("Failure", e, "Unable to retrieve networks"); }); } diff --git a/app/components/stats/statsController.js b/app/components/stats/statsController.js index a8a40a8db..8585640d1 100644 --- a/app/components/stats/statsController.js +++ b/app/components/stats/statsController.js @@ -112,7 +112,7 @@ function (Settings, $scope, Messages, $timeout, Container, ContainerTop, $stateP return d[key]; }); 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; } @@ -123,7 +123,7 @@ function (Settings, $scope, Messages, $timeout, Container, ContainerTop, $stateP updateNetworkChart(d); timeout = $timeout(updateStats, 5000); }, 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); }); } @@ -188,7 +188,7 @@ function (Settings, $scope, Messages, $timeout, Container, ContainerTop, $stateP Container.get({id: $stateParams.id}, function (d) { $scope.container = d; }, function (e) { - Messages.error("Failure", e.data); + Messages.error("Failure", e, "Unable to retrieve container info"); }); $scope.getTop(); }]); diff --git a/app/shared/services.js b/app/shared/services.js index 32848d97e..33d7532ca 100644 --- a/app/shared/services.js +++ b/app/shared/services.js @@ -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({ title: $sanitize(title), - text: $sanitize(text), + text: $sanitize(msg), time: 10000, before_open: function () { if ($('.gritter-item-wrapper').length === 4) {