mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* move node-fetch to separate package Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix node-fetch package runtime error Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix test:unit nx dependency Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix test:unit nx dependency Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * Add prepare step for node-fetch Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update lock Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove dead comment Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary fetchModuleInjectable Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Sebastian Malton <sebastian@malton.name> Co-authored-by: Sebastian Malton <sebastian@malton.name>
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
import type { JsonApiData, JsonApiError } from "./json-api";
|
|
import { JsonApi } from "./json-api";
|
|
import type { Response } from "@k8slens/node-fetch";
|
|
import type { KubeJsonApiObjectMetadata } from "./kube-object";
|
|
|
|
export interface KubeJsonApiListMetadata {
|
|
resourceVersion: string;
|
|
selfLink?: string;
|
|
}
|
|
|
|
export interface KubeJsonApiDataList<T = KubeJsonApiData> {
|
|
kind: string;
|
|
apiVersion: string;
|
|
items: T[];
|
|
metadata: KubeJsonApiListMetadata;
|
|
}
|
|
|
|
export interface KubeJsonApiData<
|
|
Metadata extends KubeJsonApiObjectMetadata = KubeJsonApiObjectMetadata,
|
|
Status = unknown,
|
|
Spec = unknown,
|
|
> extends JsonApiData {
|
|
kind: string;
|
|
apiVersion: string;
|
|
metadata: Metadata;
|
|
status?: Status;
|
|
spec?: Spec;
|
|
[otherKeys: string]: unknown;
|
|
}
|
|
|
|
export interface KubeJsonApiError extends JsonApiError {
|
|
code: number;
|
|
status: string;
|
|
message?: string;
|
|
reason: string;
|
|
details: {
|
|
name: string;
|
|
kind: string;
|
|
};
|
|
}
|
|
|
|
export class KubeJsonApi extends JsonApi<KubeJsonApiData> {
|
|
protected parseError(error: KubeJsonApiError | string, res: Response): string[] {
|
|
if (typeof error === "string") {
|
|
return [error];
|
|
}
|
|
|
|
const { status, reason, message } = error;
|
|
|
|
if (status && reason) {
|
|
return [message || `${status}: ${reason}`];
|
|
}
|
|
|
|
return super.parseError(error, res);
|
|
}
|
|
}
|