diff --git a/docs/development/core/public/kibana-plugin-core-public.httpresponse.md b/docs/development/core/public/kibana-plugin-core-public.httpresponse.md
index 80a1cb8f0263..dcbfa556da65 100644
--- a/docs/development/core/public/kibana-plugin-core-public.httpresponse.md
+++ b/docs/development/core/public/kibana-plugin-core-public.httpresponse.md
@@ -8,7 +8,7 @@
Signature:
```typescript
-export interface HttpResponse
+export interface HttpResponse
```
## Properties
diff --git a/docs/development/core/public/kibana-plugin-core-public.ihttpfetcherror.body.md b/docs/development/core/public/kibana-plugin-core-public.ihttpfetcherror.body.md
index 2a5b5067e030..d053a5a9d360 100644
--- a/docs/development/core/public/kibana-plugin-core-public.ihttpfetcherror.body.md
+++ b/docs/development/core/public/kibana-plugin-core-public.ihttpfetcherror.body.md
@@ -7,5 +7,5 @@
Signature:
```typescript
-readonly body?: any;
+readonly body?: TResponseBody;
```
diff --git a/docs/development/core/public/kibana-plugin-core-public.ihttpfetcherror.md b/docs/development/core/public/kibana-plugin-core-public.ihttpfetcherror.md
index 779cb4d3e59e..8c21d1636711 100644
--- a/docs/development/core/public/kibana-plugin-core-public.ihttpfetcherror.md
+++ b/docs/development/core/public/kibana-plugin-core-public.ihttpfetcherror.md
@@ -8,14 +8,14 @@
Signature:
```typescript
-export interface IHttpFetchError extends Error
+export interface IHttpFetchError extends Error
```
## Properties
| Property | Type | Description |
| --- | --- | --- |
-| [body](./kibana-plugin-core-public.ihttpfetcherror.body.md) | any
| |
+| [body](./kibana-plugin-core-public.ihttpfetcherror.body.md) | TResponseBody
| |
| [name](./kibana-plugin-core-public.ihttpfetcherror.name.md) | string
| |
| [req](./kibana-plugin-core-public.ihttpfetcherror.req.md) | Request
| |
| [request](./kibana-plugin-core-public.ihttpfetcherror.request.md) | Request
| |
diff --git a/docs/development/core/public/kibana-plugin-core-public.ihttpresponseinterceptoroverrides.md b/docs/development/core/public/kibana-plugin-core-public.ihttpresponseinterceptoroverrides.md
index 1e862bc4ae80..4b55cec8f3a2 100644
--- a/docs/development/core/public/kibana-plugin-core-public.ihttpresponseinterceptoroverrides.md
+++ b/docs/development/core/public/kibana-plugin-core-public.ihttpresponseinterceptoroverrides.md
@@ -9,7 +9,7 @@ Properties that can be returned by HttpInterceptor.request to override the respo
Signature:
```typescript
-export interface IHttpResponseInterceptorOverrides
+export interface IHttpResponseInterceptorOverrides
```
## Properties
diff --git a/docs/development/core/public/kibana-plugin-core-public.md b/docs/development/core/public/kibana-plugin-core-public.md
index e5fbe7c3524e..a32dceafd74a 100644
--- a/docs/development/core/public/kibana-plugin-core-public.md
+++ b/docs/development/core/public/kibana-plugin-core-public.md
@@ -97,6 +97,7 @@ The plugin integrates with the core system via lifecycle events: `setup`
| [Plugin](./kibana-plugin-core-public.plugin.md) | The interface that should be returned by a PluginInitializer
. |
| [PluginInitializerContext](./kibana-plugin-core-public.plugininitializercontext.md) | The available core services passed to a PluginInitializer
|
| [ResolvedSimpleSavedObject](./kibana-plugin-core-public.resolvedsimplesavedobject.md) | This interface is a very simple wrapper for SavedObjects resolved from the server with the [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md). |
+| [ResponseErrorBody](./kibana-plugin-core-public.responseerrorbody.md) | |
| [SavedObject](./kibana-plugin-core-public.savedobject.md) | |
| [SavedObjectAttributes](./kibana-plugin-core-public.savedobjectattributes.md) | The data for a Saved Object is stored as an object in the attributes
property. |
| [SavedObjectError](./kibana-plugin-core-public.savedobjecterror.md) | |
diff --git a/docs/development/core/public/kibana-plugin-core-public.responseerrorbody.attributes.md b/docs/development/core/public/kibana-plugin-core-public.responseerrorbody.attributes.md
new file mode 100644
index 000000000000..bf64b25c04f9
--- /dev/null
+++ b/docs/development/core/public/kibana-plugin-core-public.responseerrorbody.attributes.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [ResponseErrorBody](./kibana-plugin-core-public.responseerrorbody.md) > [attributes](./kibana-plugin-core-public.responseerrorbody.attributes.md)
+
+## ResponseErrorBody.attributes property
+
+Signature:
+
+```typescript
+attributes?: Record;
+```
diff --git a/docs/development/core/public/kibana-plugin-core-public.responseerrorbody.md b/docs/development/core/public/kibana-plugin-core-public.responseerrorbody.md
new file mode 100644
index 000000000000..8a990909fac3
--- /dev/null
+++ b/docs/development/core/public/kibana-plugin-core-public.responseerrorbody.md
@@ -0,0 +1,21 @@
+
+
+[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [ResponseErrorBody](./kibana-plugin-core-public.responseerrorbody.md)
+
+## ResponseErrorBody interface
+
+
+Signature:
+
+```typescript
+export interface ResponseErrorBody
+```
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [attributes](./kibana-plugin-core-public.responseerrorbody.attributes.md) | Record<string, unknown>
| |
+| [message](./kibana-plugin-core-public.responseerrorbody.message.md) | string
| |
+| [statusCode](./kibana-plugin-core-public.responseerrorbody.statuscode.md) | number
| |
+
diff --git a/docs/development/core/public/kibana-plugin-core-public.responseerrorbody.message.md b/docs/development/core/public/kibana-plugin-core-public.responseerrorbody.message.md
new file mode 100644
index 000000000000..a3355ddafde1
--- /dev/null
+++ b/docs/development/core/public/kibana-plugin-core-public.responseerrorbody.message.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [ResponseErrorBody](./kibana-plugin-core-public.responseerrorbody.md) > [message](./kibana-plugin-core-public.responseerrorbody.message.md)
+
+## ResponseErrorBody.message property
+
+Signature:
+
+```typescript
+message: string;
+```
diff --git a/docs/development/core/public/kibana-plugin-core-public.responseerrorbody.statuscode.md b/docs/development/core/public/kibana-plugin-core-public.responseerrorbody.statuscode.md
new file mode 100644
index 000000000000..a342bb0187d7
--- /dev/null
+++ b/docs/development/core/public/kibana-plugin-core-public.responseerrorbody.statuscode.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [ResponseErrorBody](./kibana-plugin-core-public.responseerrorbody.md) > [statusCode](./kibana-plugin-core-public.responseerrorbody.statuscode.md)
+
+## ResponseErrorBody.statusCode property
+
+Signature:
+
+```typescript
+statusCode: number;
+```
diff --git a/examples/preboot_example/public/app.tsx b/examples/preboot_example/public/app.tsx
index 364b7d5bfe8d..d95df8cf7216 100644
--- a/examples/preboot_example/public/app.tsx
+++ b/examples/preboot_example/public/app.tsx
@@ -17,7 +17,7 @@ import {
EuiText,
} from '@elastic/eui';
import React, { useEffect, useState } from 'react';
-import type { HttpSetup, IHttpFetchError } from 'src/core/public';
+import type { HttpSetup, IHttpFetchError, ResponseErrorBody } from 'src/core/public';
export const App = ({ http, token }: { http: HttpSetup; token?: string }) => {
const onCompleteSetup = async ({ shouldReloadConfig }: { shouldReloadConfig: boolean }) => {
@@ -41,7 +41,8 @@ export const App = ({ http, token }: { http: HttpSetup; token?: string }) => {
.post('/api/preboot/connect_to_es', { body: JSON.stringify(elasticsearchConfig) })
.then(
(response) => setConnectResponse(JSON.stringify(response)),
- (err: IHttpFetchError) => setConnectResponse(err?.body?.message || 'ERROR')
+ (err: IHttpFetchError) =>
+ setConnectResponse(err?.body?.message || 'ERROR')
);
};
diff --git a/src/core/public/http/fetch.test.ts b/src/core/public/http/fetch.test.ts
index d1af183e9e18..e897d69057e0 100644
--- a/src/core/public/http/fetch.test.ts
+++ b/src/core/public/http/fetch.test.ts
@@ -438,7 +438,7 @@ describe('Fetch', () => {
headers: { 'Content-Type': 'application/ndjson' },
});
- const data = await fetchInstance.post('/my/path', {
+ const data = await fetchInstance.post('/my/path', {
body,
headers: {
'Content-Type': undefined,
diff --git a/src/core/public/http/fetch.ts b/src/core/public/http/fetch.ts
index 372445b2b090..4ee81f4b47aa 100644
--- a/src/core/public/http/fetch.ts
+++ b/src/core/public/http/fetch.ts
@@ -92,9 +92,9 @@ export class Fetch {
);
if (optionsWithPath.asResponse) {
- resolve(interceptedResponse);
+ resolve(interceptedResponse as HttpResponse);
} else {
- resolve(interceptedResponse.body);
+ resolve(interceptedResponse.body as TResponseBody);
}
} catch (error) {
if (!(error instanceof HttpInterceptHaltError)) {
@@ -142,7 +142,9 @@ export class Fetch {
return new Request(url, fetchOptions as RequestInit);
}
- private async fetchResponse(fetchOptions: HttpFetchOptionsWithPath): Promise> {
+ private async fetchResponse(
+ fetchOptions: HttpFetchOptionsWithPath
+ ): Promise> {
const request = this.createRequest(fetchOptions);
let response: Response;
let body = null;
@@ -181,9 +183,15 @@ export class Fetch {
}
private shorthand(method: string): HttpHandler {
- return (pathOrOptions: string | HttpFetchOptionsWithPath, options?: HttpFetchOptions) => {
- const optionsWithPath = validateFetchArguments(pathOrOptions, options);
- return this.fetch({ ...optionsWithPath, method });
+ return (
+ pathOrOptions: string | HttpFetchOptionsWithPath,
+ options?: HttpFetchOptions
+ ) => {
+ const optionsWithPath: HttpFetchOptionsWithPath = validateFetchArguments(
+ pathOrOptions,
+ options
+ );
+ return this.fetch>({ ...optionsWithPath, method });
};
}
}
diff --git a/src/core/public/http/types.ts b/src/core/public/http/types.ts
index 4d59c52813e1..876799765ea1 100644
--- a/src/core/public/http/types.ts
+++ b/src/core/public/http/types.ts
@@ -296,18 +296,19 @@ export interface HttpFetchOptionsWithPath extends HttpFetchOptions {
* @public
*/
export interface HttpHandler {
- (path: string, options: HttpFetchOptions & { asResponse: true }): Promise<
+ (
+ path: string,
+ options: HttpFetchOptions & { asResponse: true }
+ ): Promise>;
+ (options: HttpFetchOptionsWithPath & { asResponse: true }): Promise<
HttpResponse
>;
- (options: HttpFetchOptionsWithPath & { asResponse: true }): Promise<
- HttpResponse
- >;
- (path: string, options?: HttpFetchOptions): Promise;
- (options: HttpFetchOptionsWithPath): Promise;
+ (path: string, options?: HttpFetchOptions): Promise;
+ (options: HttpFetchOptionsWithPath): Promise;
}
/** @public */
-export interface HttpResponse {
+export interface HttpResponse {
/** The original {@link HttpFetchOptionsWithPath} used to send this request. */
readonly fetchOptions: Readonly;
/** Raw request sent to Kibana server. */
@@ -322,7 +323,7 @@ export interface HttpResponse {
* Properties that can be returned by HttpInterceptor.request to override the response.
* @public
*/
-export interface IHttpResponseInterceptorOverrides {
+export interface IHttpResponseInterceptorOverrides {
/** Raw response received, may be undefined if there was an error. */
readonly response?: Readonly;
/** Parsed body received, may be undefined if there was an error. */
@@ -330,7 +331,14 @@ export interface IHttpResponseInterceptorOverrides {
}
/** @public */
-export interface IHttpFetchError extends Error {
+export interface ResponseErrorBody {
+ message: string;
+ statusCode: number;
+ attributes?: Record;
+}
+
+/** @public */
+export interface IHttpFetchError extends Error {
readonly name: string;
readonly request: Request;
readonly response?: Response;
@@ -342,7 +350,7 @@ export interface IHttpFetchError extends Error {
* @deprecated Provided for legacy compatibility. Prefer the `response` property instead.
*/
readonly res?: Response;
- readonly body?: any; // TODO: this should be unknown
+ readonly body?: TResponseBody;
}
/** @public */
diff --git a/src/core/public/index.ts b/src/core/public/index.ts
index b2d3d21a0999..40326d9c6760 100644
--- a/src/core/public/index.ts
+++ b/src/core/public/index.ts
@@ -157,6 +157,7 @@ export type {
IAnonymousPaths,
IExternalUrl,
IHttpInterceptController,
+ ResponseErrorBody,
IHttpFetchError,
IHttpResponseInterceptorOverrides,
} from './http';
diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md
index 5d63d2b6f77c..6c377bd2870a 100644
--- a/src/core/public/public.api.md
+++ b/src/core/public/public.api.md
@@ -805,17 +805,17 @@ export interface HttpFetchQuery {
// @public
export interface HttpHandler {
// (undocumented)
- (path: string, options: HttpFetchOptions & {
+ (path: string, options: HttpFetchOptions & {
asResponse: true;
}): Promise>;
// (undocumented)
- (options: HttpFetchOptionsWithPath & {
+ (options: HttpFetchOptionsWithPath & {
asResponse: true;
}): Promise>;
// (undocumented)
- (path: string, options?: HttpFetchOptions): Promise;
+ (path: string, options?: HttpFetchOptions): Promise;
// (undocumented)
- (options: HttpFetchOptionsWithPath): Promise;
+ (options: HttpFetchOptionsWithPath): Promise;
}
// @public
@@ -867,7 +867,7 @@ export interface HttpRequestInit {
}
// @public (undocumented)
-export interface HttpResponse {
+export interface HttpResponse {
readonly body?: TResponseBody;
readonly fetchOptions: Readonly;
readonly request: Readonly;
@@ -934,9 +934,9 @@ export interface IExternalUrlPolicy {
}
// @public (undocumented)
-export interface IHttpFetchError extends Error {
+export interface IHttpFetchError extends Error {
// (undocumented)
- readonly body?: any;
+ readonly body?: TResponseBody;
// (undocumented)
readonly name: string;
// @deprecated (undocumented)
@@ -956,7 +956,7 @@ export interface IHttpInterceptController {
}
// @public
-export interface IHttpResponseInterceptorOverrides {
+export interface IHttpResponseInterceptorOverrides {
readonly body?: TResponseBody;
readonly response?: Readonly;
}
@@ -1188,6 +1188,16 @@ export interface ResolvedSimpleSavedObject {
saved_object: SimpleSavedObject;
}
+// @public (undocumented)
+export interface ResponseErrorBody {
+ // (undocumented)
+ attributes?: Record;
+ // (undocumented)
+ message: string;
+ // (undocumented)
+ statusCode: number;
+}
+
// Warning: (ae-missing-release-tag) "SavedObject" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts
index d3810d8932f1..c19233809a94 100644
--- a/src/core/public/saved_objects/saved_objects_client.ts
+++ b/src/core/public/saved_objects/saved_objects_client.ts
@@ -292,7 +292,7 @@ export class SavedObjectsClient {
overwrite: options.overwrite,
};
- const createRequest: Promise> = this.savedObjectsFetch(path, {
+ const createRequest = this.savedObjectsFetch>(path, {
method: 'POST',
query,
body: JSON.stringify({
@@ -571,10 +571,10 @@ export class SavedObjectsClient {
upsert,
};
- return this.savedObjectsFetch(path, {
+ return this.savedObjectsFetch>(path, {
method: 'PUT',
body: JSON.stringify(body),
- }).then((resp: SavedObject) => {
+ }).then((resp) => {
return this.createSavedObject(resp);
});
}
@@ -588,11 +588,11 @@ export class SavedObjectsClient {
public bulkUpdate(objects: SavedObjectsBulkUpdateObject[] = []) {
const path = this.getPath(['_bulk_update']);
- return this.savedObjectsFetch(path, {
+ return this.savedObjectsFetch<{ saved_objects: Array> }>(path, {
method: 'PUT',
body: JSON.stringify(objects),
}).then((resp) => {
- resp.saved_objects = resp.saved_objects.map((d: SavedObject) => this.createSavedObject(d));
+ resp.saved_objects = resp.saved_objects.map((d) => this.createSavedObject(d));
return renameKeys<
PromiseType>,
SavedObjectsBatchResponse
@@ -624,8 +624,8 @@ export class SavedObjectsClient {
* the old kfetch error format of `{res: {status: number}}` whereas `http.fetch`
* uses `{response: {status: number}}`.
*/
- private savedObjectsFetch(path: string, { method, query, body }: HttpFetchOptions) {
- return this.http.fetch(path, { method, query, body });
+ private savedObjectsFetch(path: string, { method, query, body }: HttpFetchOptions) {
+ return this.http.fetch(path, { method, query, body });
}
}
diff --git a/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts b/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts
index 0c98d0733c64..588bac4739c5 100644
--- a/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts
+++ b/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts
@@ -56,7 +56,7 @@ export const setupValueSuggestionProvider = (
}
const requestSuggestions = memoize(
- (
+ (
index: string,
field: IFieldType,
query: string,
@@ -68,7 +68,7 @@ export const setupValueSuggestionProvider = (
) => {
usageCollector?.trackRequest();
return core.http
- .fetch(`/api/kibana/suggestions/values/${index}`, {
+ .fetch(`/api/kibana/suggestions/values/${index}`, {
method: 'POST',
body: JSON.stringify({
query,
diff --git a/src/plugins/data/public/query/saved_query/saved_query_service.ts b/src/plugins/data/public/query/saved_query/saved_query_service.ts
index 8ec9167a3a0c..17b47c78c700 100644
--- a/src/plugins/data/public/query/saved_query/saved_query_service.ts
+++ b/src/plugins/data/public/query/saved_query/saved_query_service.ts
@@ -12,14 +12,14 @@ import { SavedQueryAttributes } from '../../../common';
export const createSavedQueryService = (http: HttpStart) => {
const createQuery = async (attributes: SavedQueryAttributes, { overwrite = false } = {}) => {
- const savedQuery = await http.post('/api/saved_query/_create', {
+ const savedQuery = await http.post('/api/saved_query/_create', {
body: JSON.stringify(attributes),
});
return savedQuery;
};
const updateQuery = async (id: string, attributes: SavedQueryAttributes) => {
- const savedQuery = await http.put(`/api/saved_query/${id}`, {
+ const savedQuery = await http.put(`/api/saved_query/${id}`, {
body: JSON.stringify(attributes),
});
return savedQuery;
@@ -27,9 +27,10 @@ export const createSavedQueryService = (http: HttpStart) => {
// we have to tell the saved objects client how many to fetch, otherwise it defaults to fetching 20 per page
const getAllSavedQueries = async (): Promise => {
- const { savedQueries } = await http.post('/api/saved_query/_find', {
- body: JSON.stringify({ perPage: 10000 }),
- });
+ const { savedQueries } = await http.post<{ savedQueries: SavedQuery[] }>(
+ '/api/saved_query/_find',
+ { body: JSON.stringify({ perPage: 10000 }) }
+ );
return savedQueries;
};
@@ -39,7 +40,10 @@ export const createSavedQueryService = (http: HttpStart) => {
perPage: number = 50,
page: number = 1
): Promise<{ total: number; queries: SavedQuery[] }> => {
- const { total, savedQueries: queries } = await http.post('/api/saved_query/_find', {
+ const { total, savedQueries: queries } = await http.post<{
+ savedQueries: SavedQuery[];
+ total: number;
+ }>('/api/saved_query/_find', {
body: JSON.stringify({ page, perPage, search }),
});
@@ -47,15 +51,15 @@ export const createSavedQueryService = (http: HttpStart) => {
};
const getSavedQuery = (id: string): Promise => {
- return http.get(`/api/saved_query/${id}`);
+ return http.get(`/api/saved_query/${id}`);
};
const deleteSavedQuery = (id: string) => {
- return http.delete(`/api/saved_query/${id}`);
+ return http.delete<{}>(`/api/saved_query/${id}`);
};
const getSavedQueryCount = async (): Promise => {
- return http.get('/api/saved_query/_count');
+ return http.get('/api/saved_query/_count');
};
return {
diff --git a/src/plugins/data_views/public/data_views/data_views_api_client.ts b/src/plugins/data_views/public/data_views/data_views_api_client.ts
index d4da9a55c25d..90cc82f2a1ec 100644
--- a/src/plugins/data_views/public/data_views/data_views_api_client.ts
+++ b/src/plugins/data_views/public/data_views/data_views_api_client.ts
@@ -19,9 +19,9 @@ export class DataViewsApiClient implements IDataViewsApiClient {
this.http = http;
}
- private _request(url: string, query?: any) {
+ private _request(url: string, query?: any) {
return this.http
- .fetch(url, {
+ .fetch(url, {
query,
})
.catch((resp: any) => {
@@ -60,7 +60,9 @@ export class DataViewsApiClient implements IDataViewsApiClient {
}
async hasUserIndexPattern(): Promise {
- const response = await this._request(this._getUrl(['has_user_index_pattern']));
+ const response = await this._request<{ result: boolean }>(
+ this._getUrl(['has_user_index_pattern'])
+ );
return response.result;
}
}
diff --git a/src/plugins/es_ui_shared/public/request/send_request.ts b/src/plugins/es_ui_shared/public/request/send_request.ts
index 11ab99cfb697..bdc6386ad15c 100644
--- a/src/plugins/es_ui_shared/public/request/send_request.ts
+++ b/src/plugins/es_ui_shared/public/request/send_request.ts
@@ -31,7 +31,7 @@ export const sendRequest = async (
): Promise> => {
try {
const stringifiedBody = typeof body === 'string' ? body : JSON.stringify(body);
- const response = await httpClient[method](path, {
+ const response = await httpClient[method]<{ data?: D } & D>(path, {
body: stringifiedBody,
query,
asSystemRequest,
diff --git a/src/plugins/index_pattern_editor/public/components/index_pattern_editor_flyout_content.tsx b/src/plugins/index_pattern_editor/public/components/index_pattern_editor_flyout_content.tsx
index bbe729d4684b..5a6ad9aafdbd 100644
--- a/src/plugins/index_pattern_editor/public/components/index_pattern_editor_flyout_content.tsx
+++ b/src/plugins/index_pattern_editor/public/components/index_pattern_editor_flyout_content.tsx
@@ -167,7 +167,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
useEffect(() => {
const getRollups = async () => {
try {
- const response = await http.get('/api/rollup/indices');
+ const response = await http.get('/api/rollup/indices');
if (response) {
setRollupIndicesCapabilities(response);
}
diff --git a/src/plugins/index_pattern_management/public/components/field_editor/lib/validate_script.ts b/src/plugins/index_pattern_management/public/components/field_editor/lib/validate_script.ts
index 8c710e805234..5bff350b332a 100644
--- a/src/plugins/index_pattern_management/public/components/field_editor/lib/validate_script.ts
+++ b/src/plugins/index_pattern_management/public/components/field_editor/lib/validate_script.ts
@@ -18,7 +18,10 @@ export const executeScript = async ({
http,
}: ExecuteScriptParams): Promise => {
return http
- .post('/internal/index-pattern-management/preview_scripted_field', {
+ .post<{
+ statusCode: ExecuteScriptResult['status'];
+ body: { hits: ExecuteScriptResult['hits'] };
+ }>('/internal/index-pattern-management/preview_scripted_field', {
body: JSON.stringify({
index: indexPatternTitle,
name,
diff --git a/src/plugins/index_pattern_management/public/scripting_languages/index.ts b/src/plugins/index_pattern_management/public/scripting_languages/index.ts
index 46bb0a359ae8..f01802786ea5 100644
--- a/src/plugins/index_pattern_management/public/scripting_languages/index.ts
+++ b/src/plugins/index_pattern_management/public/scripting_languages/index.ts
@@ -21,12 +21,12 @@ export const getEnabledScriptingLanguages = (
http: HttpStart,
toasts: NotificationsStart['toasts']
) =>
- http.get('/api/kibana/scripts/languages').catch(() => {
+ http.get('/api/kibana/scripts/languages').catch(() => {
toasts.addDanger(
i18n.translate('indexPatternManagement.scriptingLanguages.errorFetchingToastDescription', {
defaultMessage: 'Error getting available scripting languages from Elasticsearch',
})
);
- return [];
+ return [] as estypes.ScriptLanguage[];
});
diff --git a/src/plugins/interactive_setup/public/progress_indicator.tsx b/src/plugins/interactive_setup/public/progress_indicator.tsx
index 73f757246af5..21bdcd2f7868 100644
--- a/src/plugins/interactive_setup/public/progress_indicator.tsx
+++ b/src/plugins/interactive_setup/public/progress_indicator.tsx
@@ -51,7 +51,7 @@ export const ProgressIndicator: FunctionComponent = ({ o
} catch (error) {
const { response, body = {} } = error as IHttpFetchError;
isAvailable = response ? response.status < 500 : undefined;
- isPastPreboot = isKibanaPastPreboot(response, body);
+ isPastPreboot = isKibanaPastPreboot(response, body as StatusResponse);
}
return isAvailable === true && isPastPreboot
? 'complete'
diff --git a/src/plugins/interactive_setup/public/submit_error_callout.tsx b/src/plugins/interactive_setup/public/submit_error_callout.tsx
index 728bbeff559d..9622d08d48b8 100644
--- a/src/plugins/interactive_setup/public/submit_error_callout.tsx
+++ b/src/plugins/interactive_setup/public/submit_error_callout.tsx
@@ -11,7 +11,7 @@ import type { FunctionComponent } from 'react';
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
-import type { IHttpFetchError } from 'kibana/public';
+import type { IHttpFetchError, ResponseErrorBody } from 'kibana/public';
import {
ERROR_CONFIGURE_FAILURE,
@@ -29,7 +29,7 @@ export interface SubmitErrorCalloutProps {
}
export const SubmitErrorCallout: FunctionComponent = (props) => {
- const error = props.error as IHttpFetchError;
+ const error = props.error as IHttpFetchError;
if (
error.body?.statusCode === 404 ||
diff --git a/src/plugins/interactive_setup/public/verification_code_form.tsx b/src/plugins/interactive_setup/public/verification_code_form.tsx
index 0f2676a80364..9ff86c63aca7 100644
--- a/src/plugins/interactive_setup/public/verification_code_form.tsx
+++ b/src/plugins/interactive_setup/public/verification_code_form.tsx
@@ -20,7 +20,7 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
-import type { IHttpFetchError } from 'kibana/public';
+import type { IHttpFetchError, ResponseErrorBody } from 'kibana/public';
import { VERIFICATION_CODE_LENGTH } from '../common';
import { SingleCharsField } from './single_chars_field';
@@ -71,7 +71,7 @@ export const VerificationCodeForm: FunctionComponent
});
} catch (error) {
if ((error as IHttpFetchError).response?.status === 403) {
- form.setError('code', (error as IHttpFetchError).body?.message);
+ form.setError('code', (error as IHttpFetchError).body?.message || '');
return;
} else {
throw error;
diff --git a/src/plugins/share/public/lib/url_shortener.ts b/src/plugins/share/public/lib/url_shortener.ts
index 6d0b7ae91e34..9a0ae9cfb0ba 100644
--- a/src/plugins/share/public/lib/url_shortener.ts
+++ b/src/plugins/share/public/lib/url_shortener.ts
@@ -29,7 +29,7 @@ export async function shortenUrl(
params: { url: relativeUrl },
});
- const resp = await post('/api/short_url', {
+ const resp = await post<{ id: string }>('/api/short_url', {
body,
});
diff --git a/src/plugins/usage_collection/public/services/create_reporter.ts b/src/plugins/usage_collection/public/services/create_reporter.ts
index e5006646fe36..fb187d1c0c48 100644
--- a/src/plugins/usage_collection/public/services/create_reporter.ts
+++ b/src/plugins/usage_collection/public/services/create_reporter.ts
@@ -22,7 +22,8 @@ export function createReporter(config: AnalyicsReporterConfig): Reporter {
debug,
storage: localStorage,
async http(report) {
- const response = await fetch.post('/api/ui_counters/_report', {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const response = await fetch.post('/api/ui_counters/_report', {
body: JSON.stringify({ report }),
asSystemRequest: true,
});
diff --git a/src/plugins/vis_types/timelion/public/components/timelion_expression_input.tsx b/src/plugins/vis_types/timelion/public/components/timelion_expression_input.tsx
index dd949f57bce2..88e6d255733e 100644
--- a/src/plugins/vis_types/timelion/public/components/timelion_expression_input.tsx
+++ b/src/plugins/vis_types/timelion/public/components/timelion_expression_input.tsx
@@ -25,7 +25,7 @@ interface TimelionExpressionInputProps {
}
function TimelionExpressionInput({ value, setValue }: TimelionExpressionInputProps) {
- const functionList = useRef([]);
+ const functionList = useRef([]);
const kibana = useKibana();
const argValueSuggestions = useMemo(getArgValueSuggestions, []);
@@ -84,7 +84,7 @@ function TimelionExpressionInput({ value, setValue }: TimelionExpressionInputPro
useEffect(() => {
if (kibana.services.http) {
- kibana.services.http.get('../api/timelion/functions').then((data) => {
+ kibana.services.http.get('../api/timelion/functions').then((data) => {
functionList.current = data;
});
}
diff --git a/test/plugin_functional/test_suites/core_plugins/execution_context.ts b/test/plugin_functional/test_suites/core_plugins/execution_context.ts
index 7dc9922dca51..6d1da821d3da 100644
--- a/test/plugin_functional/test_suites/core_plugins/execution_context.ts
+++ b/test/plugin_functional/test_suites/core_plugins/execution_context.ts
@@ -33,9 +33,10 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide
description: 'какое-то странное описание',
};
- const result = await coreStart.http.get('/execution_context/pass', {
- context,
- });
+ const result = await coreStart.http.get<{ ['x-opaque-id']: string }>(
+ '/execution_context/pass',
+ { context }
+ );
return result['x-opaque-id'];
})
diff --git a/x-pack/examples/alerting_example/public/components/view_alert.tsx b/x-pack/examples/alerting_example/public/components/view_alert.tsx
index 40eeb9fd360d..5f3581871e2b 100644
--- a/x-pack/examples/alerting_example/public/components/view_alert.tsx
+++ b/x-pack/examples/alerting_example/public/components/view_alert.tsx
@@ -38,10 +38,12 @@ export const ViewAlertPage = withRouter(({ http, id }: Props) => {
useEffect(() => {
if (!alert) {
- http.get(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}`).then(setAlert);
+ http.get(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}`).then(setAlert);
}
if (!alertState) {
- http.get(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}/state`).then(setAlertState);
+ http
+ .get(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}/state`)
+ .then(setAlertState);
}
}, [alert, alertState, http, id]);
diff --git a/x-pack/examples/alerting_example/public/components/view_astros_alert.tsx b/x-pack/examples/alerting_example/public/components/view_astros_alert.tsx
index 8eef1882b938..1bab422c2bcf 100644
--- a/x-pack/examples/alerting_example/public/components/view_astros_alert.tsx
+++ b/x-pack/examples/alerting_example/public/components/view_astros_alert.tsx
@@ -44,10 +44,14 @@ export const ViewPeopleInSpaceAlertPage = withRouter(({ http, id }: Props) => {
useEffect(() => {
if (!alert) {
- http.get(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}`).then(setAlert);
+ http
+ .get | null>(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}`)
+ .then(setAlert);
}
if (!alertState) {
- http.get(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}/state`).then(setAlertState);
+ http
+ .get(`${LEGACY_BASE_ALERT_API_PATH}/alert/${id}/state`)
+ .then(setAlertState);
}
}, [alert, alertState, http, id]);
diff --git a/x-pack/plugins/apm/public/components/app/service_map/index.tsx b/x-pack/plugins/apm/public/components/app/service_map/index.tsx
index 75d5837f738c..0ec1e6630003 100644
--- a/x-pack/plugins/apm/public/components/app/service_map/index.tsx
+++ b/x-pack/plugins/apm/public/components/app/service_map/index.tsx
@@ -168,8 +168,8 @@ export function ServiceMap({
status === FETCH_STATUS.FAILURE &&
error &&
'body' in error &&
- error.body.statusCode === 500 &&
- error.body.message === SERVICE_MAP_TIMEOUT_ERROR
+ error.body?.statusCode === 500 &&
+ error.body?.message === SERVICE_MAP_TIMEOUT_ERROR
) {
return (
diff --git a/x-pack/plugins/apm/public/hooks/use_fetcher.tsx b/x-pack/plugins/apm/public/hooks/use_fetcher.tsx
index 72fb8ac0bb3c..b77f6f9cf0fb 100644
--- a/x-pack/plugins/apm/public/hooks/use_fetcher.tsx
+++ b/x-pack/plugins/apm/public/hooks/use_fetcher.tsx
@@ -7,7 +7,7 @@
import { i18n } from '@kbn/i18n';
import React, { useEffect, useMemo, useState } from 'react';
-import { IHttpFetchError } from 'src/core/public';
+import { IHttpFetchError, ResponseErrorBody } from 'src/core/public';
import { useKibana } from '../../../../../src/plugins/kibana_react/public';
import { useTimeRangeId } from '../context/time_range_id/use_time_range_id';
import {
@@ -26,10 +26,12 @@ export enum FETCH_STATUS {
export interface FetcherResult {
data?: Data;
status: FETCH_STATUS;
- error?: IHttpFetchError;
+ error?: IHttpFetchError;
}
-function getDetailsFromErrorResponse(error: IHttpFetchError) {
+function getDetailsFromErrorResponse(
+ error: IHttpFetchError
+) {
const message = error.body?.message ?? error.response?.statusText;
return (
<>
@@ -118,7 +120,7 @@ export function useFetcher(
} as FetcherResult>);
}
} catch (e) {
- const err = e as Error | IHttpFetchError;
+ const err = e as Error | IHttpFetchError;
if (!signal.aborted) {
const errorDetails =
diff --git a/x-pack/plugins/apm/public/services/rest/callApi.ts b/x-pack/plugins/apm/public/services/rest/callApi.ts
index 9b6d0c383e9a..196878a08821 100644
--- a/x-pack/plugins/apm/public/services/rest/callApi.ts
+++ b/x-pack/plugins/apm/public/services/rest/callApi.ts
@@ -66,7 +66,7 @@ export async function callApi(
| 'delete'
| 'patch';
- const res = await http[lowercaseMethod](pathname, options);
+ const res = await http[lowercaseMethod](pathname, options);
if (isCachable(fetchOptions)) {
cache.set(cacheKey, res);
diff --git a/x-pack/plugins/canvas/public/services/kibana/custom_element.ts b/x-pack/plugins/canvas/public/services/kibana/custom_element.ts
index ec3b68d2d0bb..093373d55a3c 100644
--- a/x-pack/plugins/canvas/public/services/kibana/custom_element.ts
+++ b/x-pack/plugins/canvas/public/services/kibana/custom_element.ts
@@ -25,8 +25,8 @@ export const customElementServiceFactory: CanvasCustomElementServiceFactory = ({
create: (customElement) => http.post(apiPath, { body: JSON.stringify(customElement) }),
get: (customElementId) =>
http
- .get(`${apiPath}/${customElementId}`)
- .then(({ data: element }: { data: CustomElement }) => element),
+ .get<{ data: CustomElement }>(`${apiPath}/${customElementId}`)
+ .then(({ data: element }) => element),
update: (id, element) => http.put(`${apiPath}/${id}`, { body: JSON.stringify(element) }),
remove: (id) => http.delete(`${apiPath}/${id}`),
find: async (name) => {
diff --git a/x-pack/plugins/canvas/public/services/kibana/workpad.ts b/x-pack/plugins/canvas/public/services/kibana/workpad.ts
index 35b82735845d..9f69d5096237 100644
--- a/x-pack/plugins/canvas/public/services/kibana/workpad.ts
+++ b/x-pack/plugins/canvas/public/services/kibana/workpad.ts
@@ -63,7 +63,7 @@ export const workpadServiceFactory: CanvasWorkpadServiceFactory = ({ coreStart,
return {
get: async (id: string) => {
- const workpad = await coreStart.http.get(`${getApiPath()}/${id}`);
+ const workpad = await coreStart.http.get(`${getApiPath()}/${id}`);
return { css: DEFAULT_WORKPAD_CSS, variables: [], ...workpad };
},
diff --git a/x-pack/plugins/canvas/public/setup_expressions.ts b/x-pack/plugins/canvas/public/setup_expressions.ts
index e182d8efa097..54f1c6dbc0d9 100644
--- a/x-pack/plugins/canvas/public/setup_expressions.ts
+++ b/x-pack/plugins/canvas/public/setup_expressions.ts
@@ -26,7 +26,7 @@ export const setupExpressions = async ({
const loadServerFunctionWrappers = async () => {
if (!cached) {
cached = (async () => {
- const serverFunctionList = await coreSetup.http.get(API_ROUTE_FUNCTIONS);
+ const serverFunctionList = await coreSetup.http.get(API_ROUTE_FUNCTIONS);
const batchedFunction = bfetch.batchedFunction({ url: API_ROUTE_FUNCTIONS });
const { serialize } = serializeProvider(expressions.getTypes());
diff --git a/x-pack/plugins/canvas/public/store.ts b/x-pack/plugins/canvas/public/store.ts
index e8821bafbb05..7fe4eb21ee46 100644
--- a/x-pack/plugins/canvas/public/store.ts
+++ b/x-pack/plugins/canvas/public/store.ts
@@ -32,7 +32,7 @@ export async function createFreshStore(core: CoreSetup) {
const basePath = core.http.basePath.get();
// Retrieve server functions
- const serverFunctionsResponse = await core.http.get(API_ROUTE_FUNCTIONS);
+ const serverFunctionsResponse = await core.http.get>(API_ROUTE_FUNCTIONS);
const serverFunctions = Object.values(serverFunctionsResponse);
initialState.app = {
diff --git a/x-pack/plugins/cases/public/containers/configure/api.ts b/x-pack/plugins/cases/public/containers/configure/api.ts
index f7d0cf1ad9ae..1fd358e4dae9 100644
--- a/x-pack/plugins/cases/public/containers/configure/api.ts
+++ b/x-pack/plugins/cases/public/containers/configure/api.ts
@@ -30,10 +30,10 @@ import {
import { CaseConfigure } from './types';
export const fetchConnectors = async ({ signal }: ApiProps): Promise => {
- const response = await KibanaServices.get().http.fetch(`${CASE_CONFIGURE_CONNECTORS_URL}/_find`, {
- method: 'GET',
- signal,
- });
+ const response = await KibanaServices.get().http.fetch(
+ `${CASE_CONFIGURE_CONNECTORS_URL}/_find`,
+ { method: 'GET', signal }
+ );
return response;
};
@@ -97,10 +97,10 @@ export const patchCaseConfigure = async (
};
export const fetchActionTypes = async ({ signal }: ApiProps): Promise => {
- const response = await KibanaServices.get().http.fetch(getAllConnectorTypesUrl(), {
- method: 'GET',
- signal,
- });
+ const response = await KibanaServices.get().http.fetch(
+ getAllConnectorTypesUrl(),
+ { method: 'GET', signal }
+ );
return convertArrayToCamelCase(response) as ActionTypeConnector[];
};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_logic.ts
index 3f6436424a63..68916164f318 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_logic.ts
@@ -160,7 +160,7 @@ export const AnalyticsLogic = kea(url, { query });
actions.onAnalyticsDataLoad(response);
} catch (e) {
flashAPIErrors(e);
@@ -180,7 +180,7 @@ export const AnalyticsLogic = kea(url, { query: queryParams });
actions.onQueryDataLoad(response);
} catch (e) {
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/shared_columns.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/shared_columns.tsx
index 0b65c59a1841..e7c98332ee65 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/shared_columns.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/shared_columns.tsx
@@ -86,7 +86,7 @@ export const ACTIONS_COLUMN = {
try {
const query = (item as Query).key || (item as RecentQuery).query_string || '""';
- const response = await http.get(
+ const response = await http.get<{ id: string }>(
`/internal/app_search/engines/${engineName}/curations/find_or_create`,
{ query: { query } }
);
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/api_logs/api_logs_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/api_logs/api_logs_logic.ts
index 86c8ec8c5fbd..800e038cc192 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/api_logs/api_logs_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/api_logs/api_logs_logic.ts
@@ -104,14 +104,17 @@ export const ApiLogsLogic = kea>({
const { engineName } = EngineLogic.values;
try {
- const response = await http.get(`/internal/app_search/engines/${engineName}/api_logs`, {
- query: {
- 'page[current]': values.meta.page.current,
- 'filters[date][from]': getDateString(-1),
- 'filters[date][to]': getDateString(),
- sort_direction: 'desc',
- },
- });
+ const response = await http.get(
+ `/internal/app_search/engines/${engineName}/api_logs`,
+ {
+ query: {
+ 'page[current]': values.meta.page.current,
+ 'filters[date][from]': getDateString(-1),
+ 'filters[date][to]': getDateString(),
+ sort_direction: 'desc',
+ },
+ }
+ );
// Manual fetches (e.g. page load, user pagination) should update the view immediately,
// while polls are stored in-state until the user manually triggers the 'Refresh' action
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/components/add_domain/add_domain_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/components/add_domain/add_domain_logic.ts
index ab85f8a585d1..494d123cae12 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/components/add_domain/add_domain_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/components/add_domain/add_domain_logic.ts
@@ -23,6 +23,7 @@ import {
CrawlerDomain,
CrawlerDomainValidationResult,
CrawlerDomainValidationResultChange,
+ CrawlerDomainValidationResultFromServer,
CrawlerDomainValidationStepName,
} from '../../types';
import { crawlDomainValidationToResult, crawlerDataServerToClient } from '../../utils';
@@ -207,7 +208,7 @@ export const AddDomainLogic = kea(route, {
body: JSON.stringify({ url: values.addDomainFormInputValue.trim(), checks }),
});
const result = crawlDomainValidationToResult(data);
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_logic.ts
index 5b9960ddf54e..d1530c79a682 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_logic.ts
@@ -12,7 +12,14 @@ import { flashAPIErrors } from '../../../shared/flash_messages';
import { HttpLogic } from '../../../shared/http';
import { EngineLogic } from '../engine';
-import { CrawlerData, CrawlerDomain, CrawlEvent, CrawlRequest, CrawlerStatus } from './types';
+import {
+ CrawlerData,
+ CrawlerDomain,
+ CrawlEvent,
+ CrawlRequest,
+ CrawlerStatus,
+ CrawlerDataFromServer,
+} from './types';
import { crawlerDataServerToClient } from './utils';
const POLLING_DURATION = 1000;
@@ -104,7 +111,9 @@ export const CrawlerLogic = kea>({
const { engineName } = EngineLogic.values;
try {
- const response = await http.get(`/internal/app_search/engines/${engineName}/crawler`);
+ const response = await http.get(
+ `/internal/app_search/engines/${engineName}/crawler`
+ );
const crawlerData = crawlerDataServerToClient(response);
actions.onReceiveCrawlerData(crawlerData);
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_overview_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_overview_logic.ts
index c6a26e50a675..605d45effaa2 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_overview_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_overview_logic.ts
@@ -13,7 +13,7 @@ import { HttpLogic } from '../../../shared/http';
import { EngineLogic } from '../engine';
import { CrawlerLogic } from './crawler_logic';
-import { CrawlerDomain } from './types';
+import { CrawlerDataFromServer, CrawlerDomain } from './types';
import { crawlerDataServerToClient, getDeleteDomainSuccessMessage } from './utils';
interface CrawlerOverviewActions {
@@ -31,7 +31,7 @@ export const CrawlerOverviewLogic = kea(
`/internal/app_search/engines/${engineName}/crawler/domains/${domain.id}`,
{
query: {
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_single_domain_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_single_domain_logic.ts
index 9452ae1d578e..64687e24ccb2 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_single_domain_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/crawler/crawler_single_domain_logic.ts
@@ -16,7 +16,7 @@ import { EngineLogic, generateEnginePath } from '../engine';
import { CrawlerLogic } from './crawler_logic';
-import { CrawlerDomain, EntryPoint, Sitemap, CrawlRule } from './types';
+import { CrawlerDomain, EntryPoint, Sitemap, CrawlRule, CrawlerDomainFromServer } from './types';
import { crawlerDomainServerToClient, getDeleteDomainSuccessMessage } from './utils';
export interface CrawlerSingleDomainValues {
@@ -92,7 +92,7 @@ export const CrawlerSingleDomainLogic = kea<
const { engineName } = EngineLogic.values;
try {
- const response = await http.get(
+ const response = await http.get(
`/internal/app_search/engines/${engineName}/crawler/domains/${domainId}`
);
@@ -113,7 +113,7 @@ export const CrawlerSingleDomainLogic = kea<
};
try {
- const response = await http.put(
+ const response = await http.put(
`/internal/app_search/engines/${engineName}/crawler/domains/${domain.id}`,
{
body: JSON.stringify(payload),
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_logic.ts
index 52e1b1825b18..30380b8b41e3 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_logic.ts
@@ -239,7 +239,10 @@ export const CredentialsLogic = kea({
'page[current]': meta.page.current,
'page[size]': meta.page.size,
};
- const response = await http.get('/internal/app_search/credentials', { query });
+ const response = await http.get<{ meta: Meta; results: ApiToken[] }>(
+ '/internal/app_search/credentials',
+ { query }
+ );
actions.setCredentialsData(response.meta, response.results);
} catch (e) {
flashAPIErrors(e);
@@ -248,7 +251,9 @@ export const CredentialsLogic = kea({
fetchDetails: async () => {
try {
const { http } = HttpLogic.values;
- const response = await http.get('/internal/app_search/credentials/details');
+ const response = await http.get(
+ '/internal/app_search/credentials/details'
+ );
actions.setCredentialsDetails(response);
} catch (e) {
@@ -287,11 +292,13 @@ export const CredentialsLogic = kea({
const body = JSON.stringify(data);
if (id) {
- const response = await http.put(`/internal/app_search/credentials/${name}`, { body });
+ const response = await http.put(`/internal/app_search/credentials/${name}`, {
+ body,
+ });
actions.onApiTokenUpdateSuccess(response);
flashSuccessToast(UPDATE_MESSAGE(name));
} else {
- const response = await http.post('/internal/app_search/credentials', { body });
+ const response = await http.post('/internal/app_search/credentials', { body });
actions.onApiTokenCreateSuccess(response);
flashSuccessToast(CREATE_MESSAGE(name));
}
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/components/suggestions_logic.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/components/suggestions_logic.tsx
index 074d2114ee8c..f0100fcafac4 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/components/suggestions_logic.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/components/suggestions_logic.tsx
@@ -74,7 +74,7 @@ export const SuggestionsLogic = kea(
`/internal/app_search/engines/${engineName}/search_relevance_suggestions`,
{
body: JSON.stringify({
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/curation/curation_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/curation/curation_logic.ts
index 6393ccf97422..b5aecc417003 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/curation/curation_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/curation/curation_logic.ts
@@ -228,7 +228,7 @@ export const CurationLogic = kea(
`/internal/app_search/engines/${engineName}/curations/${props.curationId}`,
{ query: { skip_record_analytics: 'true' } }
);
@@ -248,7 +248,7 @@ export const CurationLogic = kea(
`/internal/app_search/engines/${engineName}/curations/${props.curationId}`,
{
body: JSON.stringify({
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/curations_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/curations_logic.ts
index 487072584583..422c2e857516 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/curations_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/curations_logic.ts
@@ -85,12 +85,15 @@ export const CurationsLogic = kea(
+ `/internal/app_search/engines/${engineName}/curations`,
+ {
+ query: {
+ 'page[current]': meta.page.current,
+ 'page[size]': meta.page.size,
+ },
+ }
+ );
actions.onCurationsLoad(response);
} catch (e) {
flashAPIErrors(e);
@@ -118,9 +121,10 @@ export const CurationsLogic = kea(
+ `/internal/app_search/engines/${engineName}/curations`,
+ { body: JSON.stringify({ queries }) }
+ );
navigateToUrl(generateEnginePath(ENGINE_CURATION_PATH, { curationId: response.id }));
} catch (e) {
flashAPIErrors(e);
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/views/curation_suggestion/curation_suggestion_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/views/curation_suggestion/curation_suggestion_logic.ts
index 8e6c3a9c6a6a..5c51272baea8 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/views/curation_suggestion/curation_suggestion_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/views/curation_suggestion/curation_suggestion_logic.ts
@@ -79,7 +79,8 @@ export const CurationSuggestionLogic = kea<
const { engineName } = EngineLogic.values;
try {
- const suggestionResponse = await http.get(
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const suggestionResponse = await http.get(
`/internal/app_search/engines/${engineName}/search_relevance_suggestions/${props.query}`,
{
query: {
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/views/curations_settings/curations_settings_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/views/curations_settings/curations_settings_logic.ts
index 3984cbd024da..3d090653ca74 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/views/curations_settings/curations_settings_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/curations/views/curations_settings/curations_settings_logic.ts
@@ -71,7 +71,7 @@ export const CurationsSettingsLogic = kea<
const { engineName } = EngineLogic.values;
try {
- const response = await http.get(
+ const response = await http.get<{ curation: CurationsSettings }>(
`/internal/app_search/engines/${engineName}/search_relevance_suggestions/settings`
);
actions.onCurationsSettingsLoad(response.curation);
@@ -95,7 +95,7 @@ export const CurationsSettingsLogic = kea<
const { http } = HttpLogic.values;
const { engineName } = EngineLogic.values;
try {
- const response = await http.put(
+ const response = await http.put<{ curation: CurationsSettings }>(
`/internal/app_search/engines/${engineName}/search_relevance_suggestions/settings`,
{
body: JSON.stringify({ curation: currationsSetting }),
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/document_creation/document_creation_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/document_creation/document_creation_logic.ts
index e92bc068824b..5ea2f0fe7cf7 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/document_creation/document_creation_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/document_creation/document_creation_logic.ts
@@ -181,7 +181,10 @@ export const DocumentCreationLogic = kea<
const promises = chunk(documents, CHUNK_SIZE).map((documentsChunk) => {
const body = JSON.stringify({ documents: documentsChunk });
- return http.post(`/internal/app_search/engines/${engineName}/documents`, { body });
+ return http.post(
+ `/internal/app_search/engines/${engineName}/documents`,
+ { body }
+ );
});
try {
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/document_detail_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/document_detail_logic.ts
index 25c16a7df2c5..9c41c55f5033 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/document_detail_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/document_detail_logic.ts
@@ -59,7 +59,7 @@ export const DocumentDetailLogic = kea({
try {
const { http } = HttpLogic.values;
- const response = await http.get(
+ const response = await http.get<{ fields: FieldDetails[] }>(
`/internal/app_search/engines/${engineName}/documents/${documentId}`
);
actions.setFields(response.fields);
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_logic.ts
index aa5e15a3265b..0cfe8d0c2f93 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_logic.ts
@@ -132,7 +132,9 @@ export const EngineLogic = kea>({
const { http } = HttpLogic.values;
try {
- const response = await http.get(`/internal/app_search/engines/${engineName}`);
+ const response = await http.get(
+ `/internal/app_search/engines/${engineName}`
+ );
actions.setEngineData(response);
} catch (error) {
if (error?.response?.status >= 400 && error?.response?.status < 500) {
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview_logic.ts
index 73cfef853052..878681a728e2 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview_logic.ts
@@ -84,7 +84,9 @@ export const EngineOverviewLogic = kea(
+ `/internal/app_search/engines/${engineName}/overview`
+ );
actions.onOverviewMetricsLoad(response);
} catch (e) {
flashAPIErrors(e);
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_logic.ts
index 507b83cc8b5c..c6fb1a401c59 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_logic.ts
@@ -119,7 +119,7 @@ export const EnginesLogic = kea>({
const { enginesMeta } = values;
try {
- const response = await http.get('/internal/app_search/engines', {
+ const response = await http.get('/internal/app_search/engines', {
query: {
type: 'indexed',
'page[current]': enginesMeta.page.current,
@@ -136,7 +136,7 @@ export const EnginesLogic = kea>({
const { metaEnginesMeta } = values;
try {
- const response = await http.get('/internal/app_search/engines', {
+ const response = await http.get('/internal/app_search/engines', {
query: {
type: 'meta',
'page[current]': metaEnginesMeta.page.current,
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts
index c94de74b5ab2..fd2ed0693257 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts
@@ -246,7 +246,7 @@ export const RelevanceTuningLogic = kea<
const url = `/internal/app_search/engines/${engineName}/search_settings/details`;
try {
- const response = await http.get(url);
+ const response = await http.get(url);
actions.onInitializeRelevanceTuning({
...response,
searchSettings: {
@@ -278,7 +278,7 @@ export const RelevanceTuningLogic = kea<
const filteredBoosts = removeEmptyValueBoosts(boosts);
try {
- const response = await http.post(url, {
+ const response = await http.post<{ results: Result[] }>(url, {
query: {
query,
},
@@ -313,7 +313,7 @@ export const RelevanceTuningLogic = kea<
const url = `/internal/app_search/engines/${engineName}/search_settings`;
try {
- const response = await http.put(url, {
+ const response = await http.put(url, {
body: JSON.stringify(removeBoostStateProps(values.searchSettings)),
});
flashSuccessToast(UPDATE_SUCCESS_MESSAGE, { text: SUCCESS_CHANGES_MESSAGE });
@@ -337,7 +337,7 @@ export const RelevanceTuningLogic = kea<
const url = `/internal/app_search/engines/${engineName}/search_settings/reset`;
try {
- const response = await http.post(url);
+ const response = await http.post(url);
flashSuccessToast(DELETE_SUCCESS_MESSAGE, { text: SUCCESS_CHANGES_MESSAGE });
actions.onSearchSettingsSuccess(response);
} catch (e) {
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/result_settings_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/result_settings_logic.ts
index 5ff153c3beb6..99b3e6157e22 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/result_settings_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/result_settings_logic.ts
@@ -12,13 +12,14 @@ import { i18n } from '@kbn/i18n';
import { flashAPIErrors, flashSuccessToast } from '../../../shared/flash_messages';
import { HttpLogic } from '../../../shared/http';
-import { Schema, SchemaConflicts } from '../../../shared/schema/types';
+import { Schema, SchemaConflicts, SchemaType } from '../../../shared/schema/types';
import { EngineLogic } from '../engine';
import { DEFAULT_SNIPPET_SIZE } from './constants';
import {
FieldResultSetting,
FieldResultSettingObject,
+ ServerFieldResultSetting,
ServerFieldResultSettingObject,
} from './types';
@@ -299,7 +300,11 @@ export const ResultSettingsLogic = kea;
+ schemaConflicts?: SchemaConflicts;
+ searchSettings: { result_fields: Record };
+ }>(url);
actions.initializeResultFields(serverFieldResultSettings, schema, schemaConflicts);
} catch (e) {
@@ -322,7 +327,9 @@ export const ResultSettingsLogic = kea;
+ }>(url, {
body: JSON.stringify({
result_fields: values.reducedServerResultFields,
}),
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/sample_response/sample_response_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/sample_response/sample_response_logic.ts
index d4c5a842daac..34f1478ad24f 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/sample_response/sample_response_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/sample_response/sample_response_logic.ts
@@ -14,6 +14,7 @@ import { flashAPIErrors } from '../../../../shared/flash_messages';
import { HttpLogic } from '../../../../shared/http';
import { EngineLogic } from '../../engine';
+import { FieldValue } from '../../result/types';
import { SampleSearchResponse, ServerFieldResultSettingObject } from '../types';
const NO_RESULTS_MESSAGE = i18n.translate(
@@ -71,7 +72,7 @@ export const SampleResponseLogic = kea> }>(url, {
query: { query },
body: JSON.stringify({
page: {
@@ -84,6 +85,7 @@ export const SampleResponseLogic = kea(route);
actions.setRoleMappings(response);
} catch (e) {
flashAPIErrors(e);
@@ -367,7 +367,7 @@ export const RoleMappingsLogic = kea(route);
actions.setRoleMappingsData(response);
} catch (e) {
flashAPIErrors(e);
@@ -466,7 +466,10 @@ export const RoleMappingsLogic = kea(
+ '/internal/app_search/single_user_role_mapping',
+ { body }
+ );
actions.setSingleUserRoleMapping(response);
actions.setUserCreated();
actions.initializeRoleMappings();
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/reindex_job/reindex_job_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/reindex_job/reindex_job_logic.ts
index fb50c9390a8d..e8ac47dbecbf 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/reindex_job/reindex_job_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/reindex_job/reindex_job_logic.ts
@@ -53,7 +53,7 @@ export const ReindexJobLogic = kea(
`/internal/app_search/engines/${engineName}/reindex_job/${id}`
);
actions.onLoadSuccess(response);
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/schema_base_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/schema_base_logic.ts
index b9107666a881..b299f827676d 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/schema_base_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/schema_base_logic.ts
@@ -56,7 +56,9 @@ export const SchemaBaseLogic = kea(
+ `/internal/app_search/engines/${engineName}/schema`
+ );
actions.onSchemaLoad(response);
} catch (e) {
flashAPIErrors(e);
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/schema_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/schema_logic.ts
index b26fd9206458..536a63700c5c 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/schema_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/schema_logic.ts
@@ -146,9 +146,10 @@ export const SchemaLogic = kea>({
clearFlashMessages();
try {
- const response = await http.post(`/internal/app_search/engines/${engineName}/schema`, {
- body: JSON.stringify(schema),
- });
+ const response = await http.post(
+ `/internal/app_search/engines/${engineName}/schema`,
+ { body: JSON.stringify(schema) }
+ );
actions.onSchemaLoad(response);
flashSuccessToast(successMessage || UPDATE_SCHEMA_SUCCESS);
} catch (e) {
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/search/search_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/search/search_logic.ts
index 424baedf210f..1b14b89f81a4 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/search/search_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/search/search_logic.ts
@@ -61,9 +61,10 @@ export const SearchLogic = kea>({
const { engineName } = EngineLogic.values;
try {
- const response = await http.post(`/internal/app_search/engines/${engineName}/search`, {
- query: { query },
- });
+ const response = await http.post<{ results: Result[] }>(
+ `/internal/app_search/engines/${engineName}/search`,
+ { query: { query } }
+ );
actions.onSearch(response);
} catch (e) {
flashAPIErrors(e);
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/search_ui/search_ui_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/search_ui/search_ui_logic.ts
index 7a3e429d842f..1466cfa1ff9b 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/search_ui/search_ui_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/search_ui/search_ui_logic.ts
@@ -106,7 +106,11 @@ export const SearchUILogic = kea>
const url = `/internal/app_search/engines/${engineName}/search_ui/field_config`;
try {
- const initialFieldValues = await http.get(url);
+ const initialFieldValues = await http.get<
+ InitialFieldValues & {
+ defaultValues: Pick;
+ }
+ >(url);
const {
defaultValues: { urlField, titleField },
validFields,
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/synonyms/synonyms_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/synonyms/synonyms_logic.ts
index 123a2e50fdf2..906877e79fed 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/synonyms/synonyms_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/synonyms/synonyms_logic.ts
@@ -115,12 +115,15 @@ export const SynonymsLogic = kea>
const { engineName } = EngineLogic.values;
try {
- const response = await http.get(`/internal/app_search/engines/${engineName}/synonyms`, {
- query: {
- 'page[current]': meta.page.current,
- 'page[size]': meta.page.size,
- },
- });
+ const response = await http.get(
+ `/internal/app_search/engines/${engineName}/synonyms`,
+ {
+ query: {
+ 'page[current]': meta.page.current,
+ 'page[size]': meta.page.size,
+ },
+ }
+ );
actions.onSynonymsLoad(response);
} catch (e) {
flashAPIErrors(e);
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/tables/generic_endpoint_inline_editable_table/generic_endpoint_inline_editable_table_logic.ts b/x-pack/plugins/enterprise_search/public/applications/shared/tables/generic_endpoint_inline_editable_table/generic_endpoint_inline_editable_table_logic.ts
index 9cb1061993dc..71c993dca9cb 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/tables/generic_endpoint_inline_editable_table/generic_endpoint_inline_editable_table_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/tables/generic_endpoint_inline_editable_table/generic_endpoint_inline_editable_table_logic.ts
@@ -83,7 +83,9 @@ export const GenericEndpointInlineEditableTableLogic = kea<
const { addRoute, onAdd, dataProperty } = props;
try {
- const response = await http.post(addRoute, { body: JSON.stringify(item) });
+ const response = await http.post>(addRoute, {
+ body: JSON.stringify(item),
+ });
const itemsFromResponse = response[dataProperty];
onAdd(item, itemsFromResponse);
@@ -99,7 +101,7 @@ export const GenericEndpointInlineEditableTableLogic = kea<
const { deleteRoute, onDelete, dataProperty } = props;
try {
- const response = await http.delete(deleteRoute(item));
+ const response = await http.delete>(deleteRoute(item));
const itemsFromResponse = response[dataProperty];
onDelete(item, itemsFromResponse);
@@ -116,7 +118,7 @@ export const GenericEndpointInlineEditableTableLogic = kea<
const dataToSubmit = stripIdAndCreatedAtFromItem(item);
try {
- const response = await http.put(updateRoute(item), {
+ const response = await http.put>(updateRoute(item), {
body: JSON.stringify(dataToSubmit),
});
const itemsFromResponse = response[dataProperty];
@@ -141,7 +143,7 @@ export const GenericEndpointInlineEditableTableLogic = kea<
try {
actions.setLoading();
- const response = await http.put(reorderRoute, {
+ const response = await http.put>(reorderRoute, {
body: JSON.stringify({ [dataProperty]: reorderedItemIds }),
});
const itemsFromResponse = response[dataProperty];
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.ts
index 6f09cbb15c7d..06055e956267 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.ts
@@ -392,7 +392,7 @@ export const AddSourceLogic = kea(route);
actions.setSourceConfigData(response);
} catch (e) {
flashAPIErrors(e);
@@ -415,7 +415,7 @@ export const AddSourceLogic = kea(route, { query });
actions.setSourceConnectData(response);
successCallback(response.oauthUrl);
} catch (e) {
@@ -435,7 +435,7 @@ export const AddSourceLogic = kea(route, { query });
actions.setSourceConnectData(response);
} catch (e) {
flashAPIErrors(e);
@@ -449,7 +449,7 @@ export const AddSourceLogic = kea(route);
actions.setPreContentSourceConfigData(response);
} catch (e) {
flashAPIErrors(e);
@@ -482,7 +482,7 @@ export const AddSourceLogic = kea(route, {
body: JSON.stringify(params),
});
if (successCallback) successCallback();
@@ -527,7 +527,13 @@ export const AddSourceLogic = kea(route, { query });
const { serviceName, indexPermissions, serviceType, preContentSourceId, hasConfigureStep } =
response;
@@ -574,7 +580,7 @@ export const AddSourceLogic = kea params[key] === undefined && delete params[key]);
try {
- const response = await HttpLogic.values.http.post(route, {
+ const response = await HttpLogic.values.http.post(route, {
body: JSON.stringify({ ...params }),
});
actions.setCustomSourceData(response);
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts
index 2d7667e08d8f..d62bd6252f13 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts
@@ -381,8 +381,10 @@ export const DisplaySettingsLogic = kea<
: `/internal/workplace_search/account/sources/${sourceId}/display_settings/config`;
try {
- const response = await HttpLogic.values.http.get(route);
+ const response = await HttpLogic.values.http.get(route);
actions.onInitializeDisplaySettings({
+ // isOrganization is not typed
+ // @ts-expect-error TS2345
isOrganization,
sourceId,
serverRoute: route,
@@ -396,9 +398,10 @@ export const DisplaySettingsLogic = kea<
const { searchResultConfig, serverRoute } = values;
try {
- const response = await HttpLogic.values.http.post(serverRoute, {
- body: JSON.stringify({ ...searchResultConfig }),
- });
+ const response = await HttpLogic.values.http.post(
+ serverRoute,
+ { body: JSON.stringify({ ...searchResultConfig }) }
+ );
actions.setServerResponseData(response);
} catch (e) {
flashAPIErrors(e);
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts
index d664197afaa2..218bb368e848 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts
@@ -272,7 +272,9 @@ export const SchemaLogic = kea>({
: `/internal/workplace_search/account/sources/${sourceId}/schemas`;
try {
- const response = await http.get(route);
+ const response = await http.get(route);
+ // TODO: fix
+ // @ts-expect-error TS2783
actions.onInitializeSchema({ sourceId, ...response });
} catch (e) {
flashAPIErrors(e);
@@ -287,7 +289,7 @@ export const SchemaLogic = kea>({
try {
await actions.initializeSchema();
- const response = await http.get(route);
+ const response = await http.get(route);
actions.onInitializeSchemaFieldErrors({
fieldCoercionErrors: response.fieldCoercionErrors,
});
@@ -339,7 +341,7 @@ export const SchemaLogic = kea>({
actions.resetMostRecentIndexJob(emptyReindexJob);
try {
- const response = await http.post(route, {
+ const response = await http.post(route, {
body: JSON.stringify({ ...updatedSchema }),
});
actions.onSchemaSetSuccess(response);
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/synchronization/synchronization_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/synchronization/synchronization_logic.ts
index 87a55f0e7dd3..2f4fdca44d44 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/synchronization/synchronization_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/synchronization/synchronization_logic.ts
@@ -20,10 +20,12 @@ import {
BLOCKED_TIME_WINDOWS_PATH,
getContentSourcePath,
} from '../../../../routes';
+
import {
BlockedWindow,
DayOfWeek,
IndexingSchedule,
+ ContentSourceFullData,
SyncJobType,
TimeUnit,
} from '../../../../types';
@@ -313,7 +315,7 @@ export const SynchronizationLogic = kea<
const route = `/internal/workplace_search/org/sources/${sourceId}/settings`;
try {
- const response = await HttpLogic.values.http.patch(route, {
+ const response = await HttpLogic.values.http.patch(route, {
body: JSON.stringify(body),
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.ts
index 0b67e3f2da79..e97d48889d80 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.ts
@@ -159,7 +159,9 @@ export const SourceLogic = kea>({
: `/internal/workplace_search/account/sources/${sourceId}`;
try {
- const response = await HttpLogic.values.http.get(route);
+ const response = await HttpLogic.values.http.get<
+ ContentSourceFullData & { errors?: string }
+ >(route);
actions.setContentSource(response);
if (response.isFederatedSource) {
actions.initializeFederatedSummary(sourceId);
@@ -186,7 +188,7 @@ export const SourceLogic = kea>({
initializeFederatedSummary: async ({ sourceId }) => {
const route = `/internal/workplace_search/account/sources/${sourceId}/federated_summary`;
try {
- const response = await HttpLogic.values.http.get(route);
+ const response = await HttpLogic.values.http.get<{ summary: DocumentSummaryItem[] }>(route);
actions.onUpdateSummary(response.summary);
} catch (e) {
flashAPIErrors(e);
@@ -206,7 +208,7 @@ export const SourceLogic = kea>({
} = values;
try {
- const response = await HttpLogic.values.http.post(route, {
+ const response = await HttpLogic.values.http.post(route, {
body: JSON.stringify({ query, page }),
});
actions.setSearchResults(response);
@@ -221,7 +223,7 @@ export const SourceLogic = kea>({
: `/internal/workplace_search/account/sources/${sourceId}/settings`;
try {
- const response = await HttpLogic.values.http.patch(route, {
+ const response = await HttpLogic.values.http.patch<{ name: string }>(route, {
body: JSON.stringify({ content_source: source }),
});
if (source.name) {
@@ -239,7 +241,7 @@ export const SourceLogic = kea>({
: `/internal/workplace_search/account/sources/${sourceId}`;
try {
- const response = await HttpLogic.values.http.delete(route);
+ const response = await HttpLogic.values.http.delete<{ name: string }>(route);
KibanaLogic.values.navigateToUrl(getSourcesPath(SOURCES_PATH, isOrganization));
flashSuccessToast(
i18n.translate(
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources_logic.ts
index b2c53b0a4b54..90b1f83281e9 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources_logic.ts
@@ -163,7 +163,7 @@ export const SourcesLogic = kea>(
: '/internal/workplace_search/account/sources';
try {
- const response = await HttpLogic.values.http.get(route);
+ const response = await HttpLogic.values.http.get(route);
breakpoint(); // Prevents errors if logic unmounts while fetching
actions.pollForSourceStatusChanges();
actions.onInitializeSources(response);
@@ -256,7 +256,7 @@ export const fetchSourceStatuses = async (
let response;
try {
- response = await HttpLogic.values.http.get(route);
+ response = await HttpLogic.values.http.get(route);
breakpoint();
SourcesLogic.actions.setServerSourceStatuses(response);
} catch (e) {
@@ -267,7 +267,8 @@ export const fetchSourceStatuses = async (
}
}
- return response;
+ // TODO: remove casting. return type should be ContentSourceStatus[] | undefined
+ return response as ContentSourceStatus[];
};
const updateSourcesOnToggle = (
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.ts
index 3ba7d68d0b3e..6e465854ff44 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.ts
@@ -174,7 +174,7 @@ export const GroupLogic = kea>({
listeners: ({ actions, values }) => ({
initializeGroup: async ({ groupId }) => {
try {
- const response = await HttpLogic.values.http.get(
+ const response = await HttpLogic.values.http.get(
`/internal/workplace_search/groups/${groupId}`
);
actions.onInitializeGroup(response);
@@ -220,7 +220,7 @@ export const GroupLogic = kea>({
} = values;
try {
- const response = await HttpLogic.values.http.put(
+ const response = await HttpLogic.values.http.put(
`/internal/workplace_search/groups/${id}`,
{
body: JSON.stringify({ group: { name: groupNameInputValue } }),
@@ -247,7 +247,7 @@ export const GroupLogic = kea>({
} = values;
try {
- const response = await HttpLogic.values.http.post(
+ const response = await HttpLogic.values.http.post(
`/internal/workplace_search/groups/${id}/share`,
{
body: JSON.stringify({ content_source_ids: selectedGroupSources }),
@@ -279,7 +279,7 @@ export const GroupLogic = kea>({
);
try {
- const response = await HttpLogic.values.http.put(
+ const response = await HttpLogic.values.http.put(
`/internal/workplace_search/groups/${id}/boosts`,
{
body: JSON.stringify({ content_source_boosts: boosts }),
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/groups_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/groups_logic.ts
index 19c16f6147dc..c14538346ad3 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/groups_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/groups_logic.ts
@@ -255,7 +255,9 @@ export const GroupsLogic = kea>({
listeners: ({ actions, values }) => ({
initializeGroups: async () => {
try {
- const response = await HttpLogic.values.http.get('/internal/workplace_search/groups');
+ const response = await HttpLogic.values.http.get(
+ '/internal/workplace_search/groups'
+ );
actions.onInitializeGroups(response);
} catch (e) {
flashAPIErrors(e);
@@ -288,7 +290,7 @@ export const GroupsLogic = kea>({
};
try {
- const response = await HttpLogic.values.http.post(
+ const response = await HttpLogic.values.http.post(
'/internal/workplace_search/groups/search',
{
body: JSON.stringify({
@@ -307,7 +309,7 @@ export const GroupsLogic = kea>({
fetchGroupUsers: async ({ groupId }) => {
actions.setAllGroupLoading(true);
try {
- const response = await HttpLogic.values.http.get(
+ const response = await HttpLogic.values.http.get(
`/internal/workplace_search/groups/${groupId}/group_users`
);
actions.setGroupUsers(response);
@@ -317,10 +319,13 @@ export const GroupsLogic = kea>({
},
saveNewGroup: async () => {
try {
- const response = await HttpLogic.values.http.post('/internal/workplace_search/groups', {
- body: JSON.stringify({ group_name: values.newGroupName }),
- headers,
- });
+ const response = await HttpLogic.values.http.post(
+ '/internal/workplace_search/groups',
+ {
+ body: JSON.stringify({ group_name: values.newGroupName }),
+ headers,
+ }
+ );
actions.getSearchResults(true);
const SUCCESS_MESSAGE = i18n.translate(
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/oauth_authorize/oauth_authorize_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/oauth_authorize/oauth_authorize_logic.ts
index e21cde02481a..95a8dd4b3fba 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/oauth_authorize/oauth_authorize_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/oauth_authorize/oauth_authorize_logic.ts
@@ -96,7 +96,7 @@ export const OAuthAuthorizeLogic = kea(oauthAuthorizeRoute, { query });
if (response.status === 'redirect') {
window.location.replace(response.redirect_uri);
@@ -113,7 +113,7 @@ export const OAuthAuthorizeLogic = kea(oauthAuthorizeRoute, {
body: JSON.stringify({
client_id: cachedPreAuth.clientId,
response_type: cachedPreAuth.responseType,
@@ -135,7 +135,7 @@ export const OAuthAuthorizeLogic = kea(oauthAuthorizeRoute, {
body: JSON.stringify({
client_id: cachedPreAuth.clientId,
response_type: cachedPreAuth.responseType,
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview_logic.ts
index 1d79e66e778f..494f46a8efb3 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview_logic.ts
@@ -97,7 +97,9 @@ export const OverviewLogic = kea>
listeners: ({ actions }) => ({
initializeOverview: async () => {
try {
- const response = await HttpLogic.values.http.get('/internal/workplace_search/overview');
+ const response = await HttpLogic.values.http.get(
+ '/internal/workplace_search/overview'
+ );
actions.setServerData(response);
} catch (e) {
flashAPIErrors(e);
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/role_mappings/role_mappings_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/role_mappings/role_mappings_logic.ts
index 29103aa0c39a..092b70e1f4ae 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/role_mappings/role_mappings_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/role_mappings/role_mappings_logic.ts
@@ -356,7 +356,9 @@ export const RoleMappingsLogic = kea(route);
actions.setRoleMappings(response);
} catch (e) {
flashAPIErrors(e);
@@ -367,7 +369,7 @@ export const RoleMappingsLogic = kea(route);
actions.setRoleMappingsData(response);
} catch (e) {
flashAPIErrors(e);
@@ -466,11 +468,9 @@ export const RoleMappingsLogic = kea(
'/internal/workplace_search/org/single_user_role_mapping',
- {
- body,
- }
+ { body }
);
actions.setSingleUserRoleMapping(response);
actions.setUserCreated();
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/search_authorize/search_authorize_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/search_authorize/search_authorize_logic.ts
index 852d0370e00b..9b80882ff415 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/search_authorize/search_authorize_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/search_authorize/search_authorize_logic.ts
@@ -71,7 +71,7 @@ export const SearchAuthorizeLogic = kea<
};
try {
- const response = await http.get(oauthAuthorizeRoute, { query });
+ const response = await http.get(oauthAuthorizeRoute, { query });
if (response.status === 'redirect') {
window.location.replace(response.redirect_uri);
@@ -91,7 +91,7 @@ export const SearchAuthorizeLogic = kea<
const { cachedPreAuth } = values;
try {
- const response = await http.post(oauthAuthorizeRoute, {
+ const response = await http.post<{ redirect_uri: string }>(oauthAuthorizeRoute, {
body: JSON.stringify({
client_id: cachedPreAuth.clientId,
response_type: cachedPreAuth.responseType,
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security_logic.ts
index e06504edbf0a..6484677b6df6 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security_logic.ts
@@ -138,7 +138,7 @@ export const SecurityLogic = kea>
const { http } = HttpLogic.values;
try {
- const response = await http.get(route);
+ const response = await http.get(route);
actions.setServerProps(response);
} catch (e) {
flashAPIErrors(e);
@@ -151,7 +151,7 @@ export const SecurityLogic = kea>
const { http } = HttpLogic.values;
try {
- const response = await http.patch(route, { body });
+ const response = await http.patch(route, { body });
actions.setSourceRestrictionsUpdated(response);
flashSuccessToast(SOURCE_RESTRICTIONS_SUCCESS_MESSAGE);
AppLogic.actions.setSourceRestriction(isEnabled);
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.ts
index 4faaca58ab8a..64dfa3f8e13b 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.ts
@@ -200,7 +200,7 @@ export const SettingsLogic = kea>
const route = '/internal/workplace_search/org/settings';
try {
- const response = await http.get(route);
+ const response = await http.get(route);
actions.setServerProps(response);
} catch (e) {
flashAPIErrors(e);
@@ -211,7 +211,7 @@ export const SettingsLogic = kea>
const route = '/internal/workplace_search/org/settings/connectors';
try {
- const response = await http.get(route);
+ const response = await http.get(route);
actions.onInitializeConnectors(response);
} catch (e) {
flashAPIErrors(e);
@@ -225,7 +225,9 @@ export const SettingsLogic = kea>
const body = JSON.stringify({ name });
try {
- const response = await http.put(route, { body });
+ const response = await http.put<{
+ organizationName: string;
+ }>(route, { body });
actions.setUpdatedName(response);
flashSuccessToast(ORG_UPDATED_MESSAGE);
AppLogic.actions.setOrgName(name);
@@ -240,7 +242,7 @@ export const SettingsLogic = kea>
const body = JSON.stringify({ logo });
try {
- const response = await http.put(imageRoute, { body });
+ const response = await http.put<{ logo: string | null }>(imageRoute, { body });
actions.setLogo(response.logo);
flashSuccessToast(ORG_UPDATED_MESSAGE);
} catch (e) {
@@ -255,7 +257,7 @@ export const SettingsLogic = kea>
const body = JSON.stringify({ icon });
try {
- const response = await http.put(imageRoute, { body });
+ const response = await http.put<{ icon: string | null }>(imageRoute, { body });
actions.setIcon(response.icon);
flashSuccessToast(ORG_UPDATED_MESSAGE);
} catch (e) {
@@ -275,7 +277,9 @@ export const SettingsLogic = kea>
clearFlashMessages();
try {
- const response = await http.put(route, { body });
+ const response = await http.put<{
+ oauthApplication: IOauthApplication;
+ }>(route, { body });
actions.setUpdatedOauthApplication(response);
flashSuccessToast(OAUTH_APP_UPDATED_MESSAGE);
} catch (e) {
diff --git a/x-pack/plugins/graph/public/helpers/format_http_error.ts b/x-pack/plugins/graph/public/helpers/format_http_error.ts
index 79c1bc8a4563..13ab8c02848b 100644
--- a/x-pack/plugins/graph/public/helpers/format_http_error.ts
+++ b/x-pack/plugins/graph/public/helpers/format_http_error.ts
@@ -6,9 +6,11 @@
*/
import { i18n } from '@kbn/i18n';
-import { IHttpFetchError } from 'kibana/public';
+import { IHttpFetchError, ResponseErrorBody } from 'kibana/public';
-export function formatHttpError(error: IHttpFetchError) {
+export function formatHttpError(
+ error: IHttpFetchError
+) {
if (!error.response) {
return i18n.translate('xpack.graph.fatalError.unavailableServerErrorMessage', {
defaultMessage:
@@ -20,9 +22,9 @@ export function formatHttpError(error: IHttpFetchError) {
return i18n.translate('xpack.graph.fatalError.errorStatusMessage', {
defaultMessage: 'Error {errStatus} {errStatusText}: {errMessage}',
values: {
- errStatus: error.body.status,
- errStatusText: error.body.statusText,
- errMessage: error.body.message,
+ errStatus: error.body?.status,
+ errStatusText: error.body?.statusText,
+ errMessage: error.body?.message,
},
});
}
diff --git a/x-pack/plugins/graph/public/helpers/use_graph_loader.ts b/x-pack/plugins/graph/public/helpers/use_graph_loader.ts
index c133f6bf260c..c895d4156fa7 100644
--- a/x-pack/plugins/graph/public/helpers/use_graph_loader.ts
+++ b/x-pack/plugins/graph/public/helpers/use_graph_loader.ts
@@ -7,7 +7,7 @@
import { useCallback, useState } from 'react';
import { ToastsStart } from 'kibana/public';
-import { IHttpFetchError, CoreStart } from 'kibana/public';
+import { IHttpFetchError, ResponseErrorBody, CoreStart } from 'kibana/public';
import { i18n } from '@kbn/i18n';
import { ExploreRequest, GraphExploreCallback, GraphSearchCallback, SearchRequest } from '../types';
import { formatHttpError } from './format_http_error';
@@ -21,7 +21,7 @@ export const useGraphLoader = ({ toastNotifications, coreStart }: UseGraphLoader
const [loading, setLoading] = useState(false);
const handleHttpError = useCallback(
- (error: IHttpFetchError) => {
+ (error: IHttpFetchError) => {
toastNotifications.addDanger(formatHttpError(error));
},
[toastNotifications]
@@ -59,10 +59,10 @@ export const useGraphLoader = ({ toastNotifications, coreStart }: UseGraphLoader
};
setLoading(true);
return coreStart.http
- .post('../api/graph/graphExplore', request)
+ .post<{ resp: { timed_out: unknown } }>('../api/graph/graphExplore', request)
.then(function (data) {
const response = data.resp;
- if (response.timed_out) {
+ if (response?.timed_out) {
toastNotifications.addWarning(
i18n.translate('xpack.graph.exploreGraph.timedOutWarningText', {
defaultMessage: 'Exploration timed out',
@@ -88,7 +88,7 @@ export const useGraphLoader = ({ toastNotifications, coreStart }: UseGraphLoader
};
setLoading(true);
coreStart.http
- .post('../api/graph/searchProxy', request)
+ .post<{ resp: unknown }>('../api/graph/searchProxy', request)
.then(function (data) {
const response = data.resp;
responseHandler(response);
diff --git a/x-pack/plugins/graph/public/services/fetch_top_nodes.ts b/x-pack/plugins/graph/public/services/fetch_top_nodes.ts
index 34d34317d711..1b1e91ac7277 100644
--- a/x-pack/plugins/graph/public/services/fetch_top_nodes.ts
+++ b/x-pack/plugins/graph/public/services/fetch_top_nodes.ts
@@ -96,8 +96,8 @@ export async function fetchTopNodes(
.reduce((allAggs, subAgg) => ({ ...allAggs, ...subAgg }));
const body = createSamplerSearchBody(aggs);
- const response: TopTermsAggResponse = (
- await post('../api/graph/searchProxy', {
+ const response = (
+ await post<{ resp: TopTermsAggResponse }>('../api/graph/searchProxy', {
body: JSON.stringify({ index, body }),
})
).resp;
diff --git a/x-pack/plugins/index_lifecycle_management/public/application/services/api_errors.ts b/x-pack/plugins/index_lifecycle_management/public/application/services/api_errors.ts
index fc37b62e30eb..5fcc0054cdeb 100644
--- a/x-pack/plugins/index_lifecycle_management/public/application/services/api_errors.ts
+++ b/x-pack/plugins/index_lifecycle_management/public/application/services/api_errors.ts
@@ -5,10 +5,15 @@
* 2.0.
*/
-import { IHttpFetchError } from 'src/core/public';
+import { IHttpFetchError, ResponseErrorBody } from 'src/core/public';
import { fatalErrors, toasts } from './notification';
-function createToastConfig(error: IHttpFetchError, errorTitle: string) {
+interface CommonErrorBody extends ResponseErrorBody {
+ error: string;
+ attributes: { causes: unknown[] };
+}
+
+function createToastConfig(error: IHttpFetchError, errorTitle: string) {
if (error && error.body) {
// Error body shape is defined by the API.
const { error: errorString, statusCode, message: errorMessage, attributes } = error.body;
@@ -23,7 +28,7 @@ function createToastConfig(error: IHttpFetchError, errorTitle: string) {
}
}
-export function showApiWarning(error: IHttpFetchError, errorTitle: string) {
+export function showApiWarning(error: IHttpFetchError, errorTitle: string) {
const toastConfig = createToastConfig(error, errorTitle);
if (toastConfig) {
@@ -35,7 +40,7 @@ export function showApiWarning(error: IHttpFetchError, errorTitle: string) {
return fatalErrors.add(error, errorTitle);
}
-export function showApiError(error: IHttpFetchError, errorTitle: string) {
+export function showApiError(error: IHttpFetchError, errorTitle: string) {
const toastConfig = createToastConfig(error, errorTitle);
if (toastConfig) {
diff --git a/x-pack/plugins/index_management/public/application/services/api.ts b/x-pack/plugins/index_management/public/application/services/api.ts
index 5929df2f2821..5cfb881cb22c 100644
--- a/x-pack/plugins/index_management/public/application/services/api.ts
+++ b/x-pack/plugins/index_management/public/application/services/api.ts
@@ -76,7 +76,7 @@ export async function deleteDataStreams(dataStreams: string[]) {
}
export async function loadIndices() {
- const response = await httpService.httpClient.get(`${API_BASE_PATH}/indices`);
+ const response = await httpService.httpClient.get(`${API_BASE_PATH}/indices`);
return response.data ? response.data : response;
}
@@ -87,7 +87,7 @@ export async function reloadIndices(
const body = JSON.stringify({
indexNames,
});
- const response = await httpService.httpClient.post(`${API_BASE_PATH}/indices/reload`, {
+ const response = await httpService.httpClient.post(`${API_BASE_PATH}/indices/reload`, {
body,
asSystemRequest,
});
diff --git a/x-pack/plugins/infra/public/pages/link_to/use_host_ip_to_name.ts b/x-pack/plugins/infra/public/pages/link_to/use_host_ip_to_name.ts
index f42e17c147a4..e2c25ba6fcfe 100644
--- a/x-pack/plugins/infra/public/pages/link_to/use_host_ip_to_name.ts
+++ b/x-pack/plugins/infra/public/pages/link_to/use_host_ip_to_name.ts
@@ -24,7 +24,7 @@ export const useHostIpToName = (ipAddress: string | null, indexPattern: string |
throw new Error('HTTP service is unavailable');
}
if (ipAddress && indexPattern) {
- const response = await fetch('/api/infra/ip_to_host', {
+ const response = await fetch('/api/infra/ip_to_host', {
method: 'POST',
body: JSON.stringify({
ip: ipAddress,
diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/field_item.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/field_item.tsx
index 7aa972612c82..5d8ba778e30d 100644
--- a/x-pack/plugins/lens/public/indexpattern_datasource/field_item.tsx
+++ b/x-pack/plugins/lens/public/indexpattern_datasource/field_item.tsx
@@ -165,7 +165,7 @@ export const InnerFieldItem = function InnerFieldItem(props: FieldItemProps) {
setState((s) => ({ ...s, isLoading: true }));
core.http
- .post(`/api/lens/index_stats/${indexPattern.id}/field`, {
+ .post>(`/api/lens/index_stats/${indexPattern.id}/field`, {
body: JSON.stringify({
dslQuery: esQuery.buildEsQuery(
indexPattern,
@@ -178,7 +178,7 @@ export const InnerFieldItem = function InnerFieldItem(props: FieldItemProps) {
fieldName: field.name,
}),
})
- .then((results: FieldStatsResponse) => {
+ .then((results) => {
setState((s) => ({
...s,
isLoading: false,
diff --git a/x-pack/plugins/licensing/public/plugin.ts b/x-pack/plugins/licensing/public/plugin.ts
index 1db463a47dbf..f147b560ad5d 100644
--- a/x-pack/plugins/licensing/public/plugin.ts
+++ b/x-pack/plugins/licensing/public/plugin.ts
@@ -14,6 +14,7 @@ import { createLicenseUpdate } from '../common/license_update';
import { License } from '../common/license';
import { mountExpiredBanner } from './expired_banner';
import { FeatureUsageService } from './services';
+import type { PublicLicenseJSON } from '../common/types';
export const licensingSessionStorageKey = 'xpack.licensing';
@@ -148,9 +149,9 @@ export class LicensingPlugin implements Plugin => {
+ private fetchLicense = async (core: CoreSetup): Promise => {
try {
- const response = await core.http.get({
+ const response = await core.http.get({
path: this.infoEndpoint,
asSystemRequest: true,
});
diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx
index 5a08db365613..488cafd07b69 100644
--- a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx
+++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx
@@ -460,14 +460,13 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye
if (!(this.indexPattern && this.indexPattern.title)) {
return [];
}
- let success;
- let matchingIndexes;
try {
- ({ success, matchingIndexes } = await getMatchingIndexes(this.indexPattern.title));
+ const { success, matchingIndexes } = await getMatchingIndexes(this.indexPattern.title);
+ return success ? matchingIndexes : [];
} catch (e) {
// Fail silently
+ return [];
}
- return success ? matchingIndexes : [];
}
async supportsFeatureEditing(): Promise {
diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/util/feature_edit.ts b/x-pack/plugins/maps/public/classes/sources/es_search_source/util/feature_edit.ts
index af39019c2d14..c4e12ee177f6 100644
--- a/x-pack/plugins/maps/public/classes/sources/es_search_source/util/feature_edit.ts
+++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/util/feature_edit.ts
@@ -42,7 +42,10 @@ export const deleteFeatureFromIndex = async (indexName: string, featureId: strin
};
export const getMatchingIndexes = async (indexPattern: string) => {
- return await getHttp().fetch({
+ return await getHttp().fetch<{
+ success: boolean;
+ matchingIndexes: string[];
+ }>({
path: GET_MATCHING_INDEXES_PATH,
method: 'GET',
query: { indexPattern },
@@ -50,7 +53,10 @@ export const getMatchingIndexes = async (indexPattern: string) => {
};
export const getIsDrawLayer = async (index: string) => {
- return await getHttp().fetch({
+ return await getHttp().fetch<{
+ success: boolean;
+ isDrawingIndex: boolean;
+ }>({
path: CHECK_IS_DRAWING_INDEX,
method: 'GET',
query: { index },
diff --git a/x-pack/plugins/monitoring/public/application/hooks/use_alerts_modal.ts b/x-pack/plugins/monitoring/public/application/hooks/use_alerts_modal.ts
index 123dd39f7b54..db692889e114 100644
--- a/x-pack/plugins/monitoring/public/application/hooks/use_alerts_modal.ts
+++ b/x-pack/plugins/monitoring/public/application/hooks/use_alerts_modal.ts
@@ -5,8 +5,8 @@
* 2.0.
*/
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
-import { showAlertsToast } from '../../alerts/lib/alerts_toast';
import { useRequestErrorHandler } from './use_request_error_handler';
+import { EnableAlertResponse, showAlertsToast } from '../../alerts/lib/alerts_toast';
export const useAlertsModal = () => {
const { services } = useKibana();
@@ -29,7 +29,14 @@ export const useAlertsModal = () => {
async function enableAlerts() {
try {
- const response = await services.http?.post('../api/monitoring/v1/alerts/enable', {});
+ if (!services.http?.post) {
+ throw new Error('HTTP service is unavailable');
+ }
+
+ const response = await services.http.post(
+ '../api/monitoring/v1/alerts/enable',
+ {}
+ )!;
window.localStorage.setItem('ALERTS_MODAL_DECISION_MADE', 'true');
showAlertsToast(response);
} catch (err) {
diff --git a/x-pack/plugins/monitoring/public/application/hooks/use_request_error_handler.tsx b/x-pack/plugins/monitoring/public/application/hooks/use_request_error_handler.tsx
index 6c7c86a33013..b4c2a4e86d37 100644
--- a/x-pack/plugins/monitoring/public/application/hooks/use_request_error_handler.tsx
+++ b/x-pack/plugins/monitoring/public/application/hooks/use_request_error_handler.tsx
@@ -7,14 +7,14 @@
import React, { useCallback } from 'react';
import { useHistory } from 'react-router-dom';
import { includes } from 'lodash';
-import { IHttpFetchError } from 'kibana/public';
+import { IHttpFetchError, ResponseErrorBody } from 'kibana/public';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiButton, EuiSpacer, EuiText } from '@elastic/eui';
import { formatMsg } from '../../../../../../src/plugins/kibana_legacy/public';
import { toMountPoint, useKibana } from '../../../../../../src/plugins/kibana_react/public';
import { MonitoringStartPluginDependencies } from '../../types';
-export function formatMonitoringError(err: IHttpFetchError) {
+export function formatMonitoringError(err: IHttpFetchError) {
if (err.response?.status && err.response?.status !== -1) {
return (
@@ -37,7 +37,7 @@ export const useRequestErrorHandler = () => {
const { services } = useKibana();
const history = useHistory();
return useCallback(
- (err: IHttpFetchError) => {
+ (err: IHttpFetchError) => {
if (err.response?.status === 403) {
// redirect to error message view
history.push('/access-denied');
diff --git a/x-pack/plugins/monitoring/public/application/pages/apm/instance.tsx b/x-pack/plugins/monitoring/public/application/pages/apm/instance.tsx
index 3fa7819c5e41..9f8260b4fa0d 100644
--- a/x-pack/plugins/monitoring/public/application/pages/apm/instance.tsx
+++ b/x-pack/plugins/monitoring/public/application/pages/apm/instance.tsx
@@ -59,7 +59,7 @@ export const ApmInstancePage: React.FC