Fixes assignment v comparison and null type check in metrics detail page (#95102)

* Fixes assignment v comparison and null type check in metrics detail page

* Updated docs to specify new optional TS generic

* Switches new generic to extending the interface

* Removes previously added core generic type and defaults to unknown

* Reverts unknown change, saves for later

* Reverts unknown/any change for now

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Jason Rhodes 2021-05-04 02:23:54 -04:00 committed by GitHub
parent 218abe41fe
commit 7ede7a8eca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 6 deletions

View file

@ -339,7 +339,7 @@ export interface IHttpFetchError extends Error {
* @deprecated Provided for legacy compatibility. Prefer the `response` property instead.
*/
readonly res?: Response;
readonly body?: any;
readonly body?: any; // TODO: this should be unknown
}
/** @public */

View file

@ -6,12 +6,12 @@
*/
import React, { useMemo, useState } from 'react';
import { IHttpFetchError } from 'src/core/public';
import { i18n } from '@kbn/i18n';
import { HttpHandler } from 'src/core/public';
import { ToastInput } from 'src/core/public';
import { useTrackedPromise, CanceledPromiseError } from '../utils/use_tracked_promise';
import { useKibana } from '../../../../../src/plugins/kibana_react/public';
import { InfraHttpError } from '../types';
export function useHTTPRequest<Response>(
pathname: string,
@ -25,7 +25,7 @@ export function useHTTPRequest<Response>(
const fetchService = fetch ? fetch : kibana.services.http?.fetch;
const toast = toastDanger ? toastDanger : kibana.notifications.toasts.danger;
const [response, setResponse] = useState<Response | null>(null);
const [error, setError] = useState<IHttpFetchError | null>(null);
const [error, setError] = useState<InfraHttpError | null>(null);
const [request, makeRequest] = useTrackedPromise(
{
cancelPreviousOn: 'resolution',
@ -40,7 +40,7 @@ export function useHTTPRequest<Response>(
},
onResolve: (resp) => setResponse(decode(resp)),
onReject: (e: unknown) => {
const err = e as IHttpFetchError;
const err = e as InfraHttpError;
if (e && e instanceof CanceledPromiseError) {
return;
}

View file

@ -7,13 +7,14 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { IHttpFetchError } from 'src/core/public';
import { InvalidNodeError } from './invalid_node';
import { DocumentTitle } from '../../../../components/document_title';
import { ErrorPageBody } from '../../../error';
import { InfraHttpError } from '../../../../types';
interface Props {
name: string;
error: IHttpFetchError;
error: InfraHttpError;
}
export const PageError = ({ error, name }: Props) => {

View file

@ -6,6 +6,7 @@
*/
import type { CoreSetup, CoreStart, Plugin as PluginClass } from 'kibana/public';
import { IHttpFetchError } from 'src/core/public';
import type { DataPublicPluginStart } from '../../../../src/plugins/data/public';
import type { HomePublicPluginSetup } from '../../../../src/plugins/home/public';
import type { EmbeddableSetup } from '../../../../src/plugins/embeddable/public';
@ -59,3 +60,10 @@ export type InfraClientPluginClass = PluginClass<
InfraClientSetupDeps,
InfraClientStartDeps
>;
export interface InfraHttpError extends IHttpFetchError {
readonly body?: {
statusCode: number;
message?: string;
};
}