9
9
*
10
10
* Find more information about this on the LICENSE file.
11
11
*/
12
- import axios from 'axios' ;
13
12
import { AppState } from './app-state' ;
14
13
import { ApiCheck } from './wz-api-check' ;
15
14
import { WzAuthentication } from './wz-authentication' ;
@@ -18,7 +17,7 @@ import { WazuhConfig } from './wazuh-config';
18
17
import { OdfeUtils } from '../utils' ;
19
18
import IApiResponse from './interfaces/api-response.interface' ;
20
19
import { getHttp } from '../kibana-services' ;
21
- import { PLUGIN_PLATFORM_REQUEST_HEADERS } from '../../common/constants ' ;
20
+ import { request } from '../services/request-handler ' ;
22
21
export class WzRequest {
23
22
static wazuhConfig : any ;
24
23
@@ -50,13 +49,12 @@ export class WzRequest {
50
49
const url = getHttp ( ) . basePath . prepend ( path ) ;
51
50
const options = {
52
51
method : method ,
53
- headers : { ...PLUGIN_PLATFORM_REQUEST_HEADERS , 'content-type' : 'application/json' } ,
54
- url : url ,
52
+ path : path ,
55
53
data : payload ,
56
54
timeout : timeout ,
57
55
} ;
58
56
59
- const data = await axios ( options ) ;
57
+ const data = await request ( options ) ;
60
58
61
59
if ( data [ 'error' ] ) {
62
60
throw new Error ( data [ 'error' ] ) ;
@@ -66,7 +64,7 @@ export class WzRequest {
66
64
} catch ( error ) {
67
65
OdfeUtils . checkOdfeSessionExpired ( error ) ;
68
66
//if the requests fails, we need to check if the API is down
69
- if ( checkCurrentApiIsUp ) {
67
+ if ( checkCurrentApiIsUp ) {
70
68
const currentApi = JSON . parse ( AppState . getCurrentAPI ( ) || '{}' ) ;
71
69
if ( currentApi && currentApi . id ) {
72
70
try {
@@ -100,7 +98,7 @@ export class WzRequest {
100
98
}
101
99
return errorMessage
102
100
? Promise . reject ( this . returnErrorInstance ( error , errorMessage ) )
103
- : Promise . reject ( this . returnErrorInstance ( error , 'Server did not respond' ) ) ;
101
+ : Promise . reject ( this . returnErrorInstance ( error , 'Server did not respond' ) ) ;
104
102
}
105
103
}
106
104
@@ -111,9 +109,9 @@ export class WzRequest {
111
109
* @param {Object } body Request body
112
110
*/
113
111
static async apiReq (
114
- method ,
115
- path ,
116
- body ,
112
+ method ,
113
+ path ,
114
+ body ,
117
115
options : { checkCurrentApiIsUp ?: boolean } = { checkCurrentApiIsUp : true }
118
116
) : Promise < IApiResponse < any > > {
119
117
try {
@@ -170,8 +168,8 @@ export class WzRequest {
170
168
* @param message
171
169
* @returns error
172
170
*/
173
- static returnErrorInstance ( error , message ) {
174
- if ( ! error || typeof error === 'string' ) {
171
+ static returnErrorInstance ( error , message ) {
172
+ if ( ! error || typeof error === 'string' ) {
175
173
return new Error ( message || error ) ;
176
174
}
177
175
error . message = message
0 commit comments