feat(image): define a new response handler for image deletion

pull/180/head
Anthony Lapenna 2016-09-01 14:24:47 +12:00
parent 4125361fb5
commit 789750cc86
4 changed files with 34 additions and 19 deletions

View File

@ -68,7 +68,11 @@ function ($scope, $stateParams, $state, Image, ImageHelper, Messages) {
}
}, function (e) {
$('#loadingViewSpinner').hide();
Messages.error("Unable to remove image", e.data);
if (e.data.message) {
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to remove image');
}
});
};

View File

@ -81,7 +81,11 @@ function ($scope, $state, Config, Image, Messages) {
}
complete();
}, function (e) {
Messages.error("Unable to remove image", e.data);
if (e.data.message) {
Messages.error("Failure", e.data.message);
} else {
Messages.error("Failure", 'Unable to remove image');
}
complete();
});
}
@ -104,5 +108,4 @@ function ($scope, $state, Config, Image, Messages) {
$scope.availableRegistries = c.registries;
fetchImages();
});
}]);

View File

@ -54,7 +54,6 @@ function ($scope, $state, Network, Config, Messages, errorMsgFilter) {
}
complete();
}, function (e) {
console.log(JSON.stringify(e, null, 4));
if (e.data.message) {
Messages.error("Failure", e.data.message);
} else {

View File

@ -1,3 +1,7 @@
function isJSONArray(jsonString) {
return Object.prototype.toString.call(jsonString) === '[object Array]';
}
function isJSON(jsonString) {
try {
var o = JSON.parse(jsonString);
@ -17,30 +21,35 @@ function jsonObjectsToArrayHandler(data) {
return angular.fromJson(str);
}
// Image delete API returns an array on success and a string on error.
// This handler creates an array composed of a single object with a field 'message'
// from a string in case of error.
// Image delete API returns an array on success (Docker 1.9 -> Docker 1.12).
// On error, it returns either an error message as a string (Docker < 1.12) or a JSON object with the field message
// container the error (Docker = 1.12).
// This handler returns the original array on success or a newly created array containing
// only one JSON object with the field message filled with the error message on failure.
function deleteImageHandler(data) {
var response;
var response = [];
// A string is returned on failure (Docker < 1.12)
if (!isJSON(data)) {
var arr = [];
response = {};
response.message = data;
arr.push(response);
console.log(JSON.stringify(arr, null, 4));
return arr;
response.push({message: data});
}
// A JSON object is returned on failure (Docker = 1.12)
else if (!isJSONArray) {
var json = angular.fromJson(data);
response.push(json);
}
// An array is returned on success (Docker 1.9 -> 1.12)
else {
response = angular.fromJson(data);
}
return response;
}
// Network delete API returns an empty string on success.
// Network delete API returns an empty string on success (Docker 1.9 -> Docker 1.12).
// On error, it returns either an error message as a string (Docker < 1.12) or a JSON object with the field message
// container the error (Docker = 1.12).
// This handler returns an empty object on success or a JSON object with the field message container the error message
// on failure.
// This handler returns an empty object on success or a newly created JSON object with
// the field message containing the error message on failure.
function deleteNetworkHandler(data) {
console.log(JSON.stringify(data, null, 4));
var response = {};
// No data is returned when deletion is successful (Docker 1.9 -> 1.12)
if (!data) {