wazuh-kibana-app/public/objects/apiReq.js

39 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-05-25 16:29:54 +00:00
import chrome from 'ui/chrome';
2016-08-11 12:14:42 +00:00
require('ui/modules').get('app/wazuh', [])
.service('apiReq', function ($q, $http, genericReq) {
2016-08-11 12:14:42 +00:00
return {
request: function (method, path, body) {
var defered = $q.defer();
var promise = defered.promise;
if (!method || !path || !body) {
defered.reject({ 'error': -1, 'message': 'Missing parameters' });
return promise;
}
var requestData = {
'method': method,
'path': path,
'body': body
}
genericReq.request('POST', '/api/wazuh-api/request', requestData)
.then(function (data) {
2016-08-11 12:14:42 +00:00
if (data.error) {
defered.reject(data);
} else {
defered.resolve(data);
}
}, function (data) {
2016-08-11 12:14:42 +00:00
if (data.error) {
defered.reject(data);
} else {
defered.reject({ 'error': -2, 'message': 'Error doing a request to Kibana API.' });
}
});
return promise;
}
};
2017-05-25 16:29:54 +00:00
});