wazuh-kibana-app/public/services/apiReq.js
Jesús Ángel González Novez 6a85d36bff Better performance on apiReq
2017-10-30 10:14:36 +01:00

42 lines
1.3 KiB
JavaScript

import chrome from 'ui/chrome';
require('ui/modules')
.get('app/wazuh', [])
.service('apiReq', function ($q, $http, genericReq) {
return {
request: (method, path, body) => {
let defered = $q.defer();
if (!method || !path || !body) {
defered.reject({
error: -1,
message: 'Missing parameters'
});
return defered.promise;
}
let requestData = { method, path, body };
genericReq
.request('POST', '/api/wazuh-api/request', requestData)
.then((data) => {
if (data.error) {
defered.reject(data);
} else {
defered.resolve(data);
}
})
.catch((error) => {
if (error.error) {
defered.reject(error);
} else {
defered.reject({
error: -2,
message: 'Error doing a request to Kibana API.'
});
}
});
return defered.promise;
}
};
});