From 5432424a4086dba523e6e3bdc5c1f46a4ccf68ac Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Wed, 31 Aug 2016 11:26:02 +1200 Subject: [PATCH] fix(image): fix the deleteImageHandler so that messages are correctly displayed in the UI (#172) --- app/shared/responseHandlers.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/shared/responseHandlers.js b/app/shared/responseHandlers.js index 54d7105cb..fff403036 100644 --- a/app/shared/responseHandlers.js +++ b/app/shared/responseHandlers.js @@ -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);