fix(image): fix the deleteImageHandler so that messages are correctly displayed in the UI (#172)

pull/174/head
Anthony Lapenna 2016-08-31 11:26:02 +12:00 committed by GitHub
parent e81bfb6f37
commit 5432424a40
1 changed files with 13 additions and 1 deletions

View File

@ -1,3 +1,14 @@
function isJSON(jsonString) {
try {
var o = JSON.parse(jsonString);
if (o && typeof o === "object") {
return o;
}
}
catch (e) { }
return false;
}
// The Docker API often returns a list of JSON object.
// This handler wrap the JSON objects in an array.
// Used by the API in: Image push, Image create, Events query.
@ -11,11 +22,12 @@ function jsonObjectsToArrayHandler(data) {
// from a string in case of error.
function deleteImageHandler(data) {
var response;
if (!Array.isArray(data)) {
if (!isJSON(data)) {
var arr = [];
response = {};
response.message = data;
arr.push(response);
console.log(JSON.stringify(arr, null, 4));
return arr;
}
response = angular.fromJson(data);