From f1f258b8f9ed1d6a290448bd6634c2d6b43a19de Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 6 Sep 2018 14:42:51 -0400 Subject: [PATCH] same for destroy --- embark-ui/src/services/api.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/embark-ui/src/services/api.js b/embark-ui/src/services/api.js index dc3282542..7bc643651 100644 --- a/embark-ui/src/services/api.js +++ b/embark-ui/src/services/api.js @@ -31,13 +31,18 @@ function post(path, params = {}) { }); } -function destroy(path, params) { +function destroy(path, params = {}) { + const callback = params.callback || function(){}; return axios.delete(constants.httpEndpoint + path, params) .then((response) => { - return {response, error: null}; + const data = (response.data && response.data.error) ? {error: response.data.error} : {response, error: null}; + callback(data.error, data.response); + return data; }) .catch((error) => { - return {response: null, error: error.message || 'Something bad happened'}; + const data = {response: null, error: error.message || 'Something bad happened'}; + callback(data.error, data.response); + return data; }); }