mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 18:05:20 +00:00
Adapting services to new error handler module
This commit is contained in:
parent
75e3f3588f
commit
4b7258de24
@ -30,14 +30,7 @@ require('ui/modules').get('app/wazuh', []).service('apiReq', function ($q, $http
|
||||
defered.resolve(data);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if(error.status && error.status === 401){
|
||||
appState.removeUserCode();
|
||||
defered.reject(error);
|
||||
$location.path('/login');
|
||||
}
|
||||
defered.reject(error);
|
||||
});
|
||||
.catch(error => defered.reject(error));
|
||||
|
||||
return defered.promise;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
const prepError = require('plugins/wazuh/services/prep-error');
|
||||
import chrome from 'ui/chrome';
|
||||
|
||||
require('ui/modules').get('app/wazuh', []).service('genericReq', function ($q, $http, $location, $rootScope, appState) {
|
||||
require('ui/modules').get('app/wazuh', []).service('genericReq', function ($q, $http, $location, $rootScope, appState,errorHandler) {
|
||||
|
||||
const _request = (method, url, payload = null) => {
|
||||
let defered = $q.defer();
|
||||
@ -40,11 +40,7 @@ require('ui/modules').get('app/wazuh', []).service('genericReq', function ($q, $
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if(error.status && error.status === 401){
|
||||
appState.removeUserCode();
|
||||
defered.reject(error);
|
||||
$location.path('/login');
|
||||
} else if(error.status && error.status === -1){
|
||||
if(error.status && error.status === -1){
|
||||
defered.reject({data: 'request_timeout_genericreq', url });
|
||||
}else {
|
||||
defered.reject(error);
|
||||
@ -70,9 +66,7 @@ require('ui/modules').get('app/wazuh', []).service('genericReq', function ($q, $
|
||||
.then((data) => defered.resolve(data))
|
||||
.catch(error => {
|
||||
if(error.status && error.status === 401){
|
||||
appState.removeUserCode();
|
||||
defered.reject(error);
|
||||
$location.path('/login');
|
||||
} else {
|
||||
defered.reject(prepError(error));
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ const healthCheck = ($window, $rootScope) => {
|
||||
};
|
||||
|
||||
//Installation wizard
|
||||
const settingsWizard = ($rootScope, $location, $q, $window, Notifier, testAPI, appState, genericReq) => {
|
||||
const settingsWizard = ($rootScope, $location, $q, $window, Notifier, testAPI, appState, genericReq, errorHandler) => {
|
||||
const notify = new Notifier();
|
||||
let deferred = $q.defer();
|
||||
|
||||
@ -26,12 +26,12 @@ const settingsWizard = ($rootScope, $location, $q, $window, Notifier, testAPI, a
|
||||
|
||||
const checkResponse = data => {
|
||||
if (parseInt(data.data.error) === 2){
|
||||
notify.warning("Wazuh App: Please set up Wazuh API credentials.");
|
||||
errorHandler.handle('Wazuh App: Please set up Wazuh API credentials.',true);
|
||||
} else if(data.data.data && data.data.data.apiIsDown){
|
||||
$rootScope.apiIsDown = "down";
|
||||
notify.error('Wazuh RESTful API seems to be down.');
|
||||
errorHandler.handle('Wazuh RESTful API seems to be down.');
|
||||
} else {
|
||||
notify.error('Could not connect with Wazuh RESTful API.');
|
||||
errorHandler.handle('Could not connect with Wazuh RESTful API.');
|
||||
appState.removeCurrentAPI();
|
||||
}
|
||||
$rootScope.comeFromWizard = true;
|
||||
@ -68,7 +68,7 @@ const settingsWizard = ($rootScope, $location, $q, $window, Notifier, testAPI, a
|
||||
changeCurrentApi(data);
|
||||
}
|
||||
})
|
||||
.catch(error => notify.error(error.message));
|
||||
.catch(error => errorHandler.handle(error));
|
||||
}
|
||||
|
||||
if (!$location.path().includes("/health-check") && healthCheck($window, $rootScope)) {
|
||||
@ -78,20 +78,20 @@ const settingsWizard = ($rootScope, $location, $q, $window, Notifier, testAPI, a
|
||||
// There's no cookie for current API
|
||||
if (!appState.getCurrentAPI()) {
|
||||
genericReq.request('GET', '/api/wazuh-api/apiEntries')
|
||||
.then((data) => {
|
||||
.then(data => {
|
||||
if (data.data.length > 0) {
|
||||
var apiEntries = data.data;
|
||||
const apiEntries = data.data;
|
||||
appState.setCurrentAPI(JSON.stringify({name: apiEntries[0]._source.cluster_info.manager, id: apiEntries[0]._id }));
|
||||
callCheckStored();
|
||||
} else {
|
||||
notify.warning("Wazuh App: Please set up Wazuh API credentials.");
|
||||
errorHandler.handle('Wazuh App: Please set up Wazuh API credentials.',true);
|
||||
$rootScope.comeFromWizard = true;
|
||||
if(!$location.path().includes("/settings")) $location.path('/settings');
|
||||
deferred.reject();
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
notify.error("Error getting API entries due to " + error);
|
||||
.catch(error => {
|
||||
errorHandler.handle(error);
|
||||
$rootScope.comeFromWizard = true;
|
||||
if(!$location.path().includes("/settings")) $location.path('/settings');
|
||||
deferred.reject();
|
||||
|
@ -1,13 +1,12 @@
|
||||
import chrome from 'ui/chrome';
|
||||
require('ui/modules').get('app/wazuh', [])
|
||||
.service('testAPI', function ($q, $http, $location, $rootScope, appState) {
|
||||
const app = require('ui/modules').get('app/wazuh', []);
|
||||
|
||||
app.service('testAPI', function ($q, $http, $location, $rootScope, appState) {
|
||||
return {
|
||||
check_stored: data => {
|
||||
const headers = {headers:{ "Content-Type": 'application/json' },timeout: 4000};
|
||||
console.log(appState.getUserCode())
|
||||
if(appState.getUserCode()) headers.headers.code = appState.getUserCode();
|
||||
let defered = $q.defer();
|
||||
console.log(data);
|
||||
$http
|
||||
.post(chrome.addBasePath('/api/wazuh-api/checkStoredAPI'), data,headers)
|
||||
.then(response => {
|
||||
@ -18,11 +17,7 @@ require('ui/modules').get('app/wazuh', [])
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if(error.status && error.status === 401){
|
||||
appState.removeUserCode();
|
||||
defered.reject(error);
|
||||
$location.path('/login');
|
||||
} else if(error.status && error.status === -1){
|
||||
if(error.status && error.status === -1){
|
||||
defered.reject({data: 'request_timeout_checkstored'});
|
||||
} else {
|
||||
defered.reject(error);
|
||||
@ -45,11 +40,7 @@ require('ui/modules').get('app/wazuh', [])
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if(error.status && error.status === 401){
|
||||
appState.removeUserCode();
|
||||
defered.reject(error);
|
||||
$location.path('/login');
|
||||
} else if(error.data && error.data.message && error.data.message.includes('ENOTFOUND')) {
|
||||
if(error.data && error.data.message && error.data.message.includes('ENOTFOUND')) {
|
||||
defered.reject({data: 'invalid_url'});
|
||||
} else if(error.data && error.data.message && error.data.message.includes('ECONNREFUSED')) {
|
||||
defered.reject({data: 'invalid_port'});
|
||||
|
Loading…
Reference in New Issue
Block a user