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; }); }