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:
parent
58cbf5f300
commit
8761aa1b4a
20
src/common/fetch/create-headers.injectable.ts
Normal file
20
src/common/fetch/create-headers.injectable.ts
Normal 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;
|
||||||
@ -10,11 +10,7 @@ export type Fetch = (url: string, init?: RequestInit) => Promise<Response>;
|
|||||||
|
|
||||||
const fetchInjectable = getInjectable({
|
const fetchInjectable = getInjectable({
|
||||||
id: "fetch",
|
id: "fetch",
|
||||||
instantiate: (di): Fetch => {
|
instantiate: (di): Fetch => di.inject(nodeFetchModuleInjectable).default,
|
||||||
const { default: fetch } = di.inject(nodeFetchModuleInjectable);
|
|
||||||
|
|
||||||
return (url, init) => fetch(url, init);
|
|
||||||
},
|
|
||||||
causesSideEffects: true,
|
causesSideEffects: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import FormData from "form-data";
|
import FormData from "form-data";
|
||||||
import type { Cluster } from "../common/cluster/cluster";
|
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 type { RequestMetricsParams } from "../common/k8s-api/endpoints/metrics.api/request-metrics.injectable";
|
||||||
import k8sRequestInjectable from "./k8s-request.injectable";
|
import k8sRequestInjectable from "./k8s-request.injectable";
|
||||||
|
|
||||||
@ -29,8 +30,10 @@ const getMetricsInjectable = getInjectable({
|
|||||||
body.append(key, value);
|
body.append(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const controller = withTimeout(60 * 1000); // 1 minute timeout
|
||||||
|
|
||||||
return k8sRequest(cluster, metricsPath, {
|
return k8sRequest(cluster, metricsPath, {
|
||||||
timeout: 0,
|
signal: controller.signal,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body,
|
body,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -277,7 +277,7 @@ export class Kubectl {
|
|||||||
|
|
||||||
const response = await this.dependencies.fetch(this.url, { compress: true });
|
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");
|
throw new Error("Body missing or not readable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user