diff --git a/x-pack/legacy/plugins/siem/public/components/ml/api/anomalies_table_data.ts b/x-pack/legacy/plugins/siem/public/components/ml/api/anomalies_table_data.ts index 35dbbf012272e..b3876b28655b3 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/api/anomalies_table_data.ts +++ b/x-pack/legacy/plugins/siem/public/components/ml/api/anomalies_table_data.ts @@ -5,7 +5,6 @@ */ import { Anomalies, InfluencerInput, CriteriaFields } from '../types'; -import { throwIfNotOk } from '../../../hooks/api/api'; import { KibanaServices } from '../../../lib/kibana'; export interface Body { @@ -22,17 +21,10 @@ export interface Body { } export const anomaliesTableData = async (body: Body, signal: AbortSignal): Promise => { - const response = await KibanaServices.get().http.fetch( - '/api/ml/results/anomalies_table_data', - { - method: 'POST', - body: JSON.stringify(body), - asResponse: true, - asSystemRequest: true, - signal, - } - ); - - await throwIfNotOk(response.response); - return response.body!; + return KibanaServices.get().http.fetch('/api/ml/results/anomalies_table_data', { + method: 'POST', + body: JSON.stringify(body), + asSystemRequest: true, + signal, + }); }; diff --git a/x-pack/legacy/plugins/siem/public/components/ml/api/get_ml_capabilities.ts b/x-pack/legacy/plugins/siem/public/components/ml/api/get_ml_capabilities.ts index feafbba2024dc..e69abc1a86e0e 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/api/get_ml_capabilities.ts +++ b/x-pack/legacy/plugins/siem/public/components/ml/api/get_ml_capabilities.ts @@ -5,7 +5,6 @@ */ import { InfluencerInput, MlCapabilities } from '../types'; -import { throwIfNotOk } from '../../../hooks/api/api'; import { KibanaServices } from '../../../lib/kibana'; export interface Body { @@ -22,16 +21,9 @@ export interface Body { } export const getMlCapabilities = async (signal: AbortSignal): Promise => { - const response = await KibanaServices.get().http.fetch( - '/api/ml/ml_capabilities', - { - method: 'GET', - asResponse: true, - asSystemRequest: true, - signal, - } - ); - - await throwIfNotOk(response.response); - return response.body!; + return KibanaServices.get().http.fetch('/api/ml/ml_capabilities', { + method: 'GET', + asSystemRequest: true, + signal, + }); }; diff --git a/x-pack/legacy/plugins/siem/public/components/ml_popover/api.tsx b/x-pack/legacy/plugins/siem/public/components/ml_popover/api.tsx index 120fd8c404ffd..145d83cbb2cf1 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml_popover/api.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml_popover/api.tsx @@ -18,7 +18,6 @@ import { StopDatafeedResponse, } from './types'; import { throwIfErrorAttached, throwIfErrorAttachedToSetup } from '../ml/api/throw_if_not_ok'; -import { throwIfNotOk } from '../../hooks/api/api'; import { KibanaServices } from '../../lib/kibana'; /** @@ -31,18 +30,14 @@ export const checkRecognizer = async ({ indexPatternName, signal, }: CheckRecognizerProps): Promise => { - const response = await KibanaServices.get().http.fetch( + return KibanaServices.get().http.fetch( `/api/ml/modules/recognize/${indexPatternName}`, { method: 'GET', - asResponse: true, asSystemRequest: true, signal, } ); - - await throwIfNotOk(response.response); - return response.body!; }; /** @@ -52,18 +47,11 @@ export const checkRecognizer = async ({ * @param signal to cancel request */ export const getModules = async ({ moduleId = '', signal }: GetModulesProps): Promise => { - const response = await KibanaServices.get().http.fetch( - `/api/ml/modules/get_module/${moduleId}`, - { - method: 'GET', - asResponse: true, - asSystemRequest: true, - signal, - } - ); - - await throwIfNotOk(response.response); - return response.body!; + return KibanaServices.get().http.fetch(`/api/ml/modules/get_module/${moduleId}`, { + method: 'GET', + asSystemRequest: true, + signal, + }); }; /** @@ -93,16 +81,12 @@ export const setupMlJob = async ({ startDatafeed: false, useDedicatedIndex: true, }), - asResponse: true, asSystemRequest: true, } ); - await throwIfNotOk(response.response); - const json = response.body!; - throwIfErrorAttachedToSetup(json, jobIdErrorFilter); - - return json; + throwIfErrorAttachedToSetup(response, jobIdErrorFilter); + return response; }; /** @@ -126,16 +110,12 @@ export const startDatafeeds = async ({ datafeedIds, ...(start !== 0 && { start }), }), - asResponse: true, asSystemRequest: true, } ); - await throwIfNotOk(response.response); - const json = response.body!; - throwIfErrorAttached(json, datafeedIds); - - return json; + throwIfErrorAttached(response, datafeedIds); + return response; }; /** @@ -155,14 +135,10 @@ export const stopDatafeeds = async ({ body: JSON.stringify({ datafeedIds, }), - asResponse: true, asSystemRequest: true, } ); - await throwIfNotOk(stopDatafeedsResponse.response); - const stopDatafeedsResponseJson = stopDatafeedsResponse.body!; - const datafeedPrefix = 'datafeed-'; const closeJobsResponse = await KibanaServices.get().http.fetch( '/api/ml/jobs/close_jobs', @@ -175,13 +151,11 @@ export const stopDatafeeds = async ({ : dataFeedId ), }), - asResponse: true, asSystemRequest: true, } ); - await throwIfNotOk(closeJobsResponse.response); - return [stopDatafeedsResponseJson, closeJobsResponse.body!]; + return [stopDatafeedsResponse, closeJobsResponse]; }; /** @@ -193,17 +167,10 @@ export const stopDatafeeds = async ({ * @param signal to cancel request */ export const getJobsSummary = async (signal: AbortSignal): Promise => { - const response = await KibanaServices.get().http.fetch( - '/api/ml/jobs/jobs_summary', - { - method: 'POST', - body: JSON.stringify({}), - asResponse: true, - asSystemRequest: true, - signal, - } - ); - - await throwIfNotOk(response.response); - return response.body!; + return KibanaServices.get().http.fetch('/api/ml/jobs/jobs_summary', { + method: 'POST', + body: JSON.stringify({}), + asSystemRequest: true, + signal, + }); };