1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-11-14 12:35:29 -05:00
parent 58cbf5f300
commit 8761aa1b4a
4 changed files with 26 additions and 7 deletions

View File

@ -0,0 +1,20 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { Headers, HeadersInit } from "node-fetch";
import nodeFetchModuleInjectable from "./fetch-module.injectable";
export type CreateHeaders = (init?: HeadersInit) => Headers;
const createHeadersInjectable = getInjectable({
id: "create-headers",
instantiate: (di): CreateHeaders => {
const { Headers } = di.inject(nodeFetchModuleInjectable);
return (init) => new Headers(init);
},
});
export default createHeadersInjectable;

View File

@ -10,11 +10,7 @@ export type Fetch = (url: string, init?: RequestInit) => Promise<Response>;
const fetchInjectable = getInjectable({
id: "fetch",
instantiate: (di): Fetch => {
const { default: fetch } = di.inject(nodeFetchModuleInjectable);
return (url, init) => fetch(url, init);
},
instantiate: (di): Fetch => di.inject(nodeFetchModuleInjectable).default,
causesSideEffects: true,
});

View File

@ -5,6 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import FormData from "form-data";
import type { Cluster } from "../common/cluster/cluster";
import { withTimeout } from "../common/fetch/timeout-controller";
import type { RequestMetricsParams } from "../common/k8s-api/endpoints/metrics.api/request-metrics.injectable";
import k8sRequestInjectable from "./k8s-request.injectable";
@ -29,8 +30,10 @@ const getMetricsInjectable = getInjectable({
body.append(key, value);
}
const controller = withTimeout(60 * 1000); // 1 minute timeout
return k8sRequest(cluster, metricsPath, {
timeout: 0,
signal: controller.signal,
method: "POST",
body,
});

View File

@ -277,7 +277,7 @@ export class Kubectl {
const response = await this.dependencies.fetch(this.url, { compress: true });
if (!response.body || !response.body.readable) {
if (!response.body || !response.body.readable || response.status !== 200) {
throw new Error("Body missing or not readable");
}