diff --git a/packages/core/src/common/k8s-api/json-api.ts b/packages/core/src/common/k8s-api/json-api.ts
index 00325f3853..ad29cfae4c 100644
--- a/packages/core/src/common/k8s-api/json-api.ts
+++ b/packages/core/src/common/k8s-api/json-api.ts
@@ -26,6 +26,30 @@ export interface JsonApiError {
errors?: { id: string; title: string; status?: number }[];
}
+export interface KubeJsonApiErrorCause {
+ reason: string;
+ message: string;
+ field: string;
+}
+
+export interface KubeJsonApiErrorDetails {
+ name: string;
+ group: string;
+ kind: string;
+ causes: KubeJsonApiErrorCause[];
+}
+
+export interface KubeJsonApiError {
+ kind: "Status";
+ apiVersion: "v1";
+ metadata: object;
+ status: string;
+ message: string;
+ reason: string;
+ details: KubeJsonApiErrorDetails;
+ code: number;
+}
+
export interface JsonApiParams {
data?: PartialDeep; // request body
}
@@ -246,7 +270,7 @@ export class JsonApi = Js
export class JsonApiErrorParsed {
isUsedForNotification = false;
- constructor(private error: JsonApiError | DOMException, private messages: string[]) {
+ constructor(private error: JsonApiError | DOMException | KubeJsonApiError, private messages: string[]) {
}
get isAborted() {
diff --git a/packages/core/src/features/cluster/namespaces/__snapshots__/edit-namespace-from-new-tab.test.tsx.snap b/packages/core/src/features/cluster/namespaces/__snapshots__/edit-namespace-from-new-tab.test.tsx.snap
index be7ad3680d..6eafa73d66 100644
--- a/packages/core/src/features/cluster/namespaces/__snapshots__/edit-namespace-from-new-tab.test.tsx.snap
+++ b/packages/core/src/features/cluster/namespaces/__snapshots__/edit-namespace-from-new-tab.test.tsx.snap
@@ -10334,6 +10334,758 @@ metadata:
+
+
+
+
+
+
+
+
+
+ close
+
+
+
+ Close
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/core/src/features/cluster/namespaces/edit-namespace-from-new-tab.test.tsx b/packages/core/src/features/cluster/namespaces/edit-namespace-from-new-tab.test.tsx
index f11fbe87de..3d0651b848 100644
--- a/packages/core/src/features/cluster/namespaces/edit-namespace-from-new-tab.test.tsx
+++ b/packages/core/src/features/cluster/namespaces/edit-namespace-from-new-tab.test.tsx
@@ -25,13 +25,16 @@ import apiKubePatchInjectable from "../../../renderer/k8s/api-kube-patch.injecta
import apiKubeGetInjectable from "../../../renderer/k8s/api-kube-get.injectable";
import type { KubeJsonApiData } from "../../../common/k8s-api/kube-json-api";
import type { BaseKubeJsonApiObjectMetadata, KubeObjectScope } from "../../../common/k8s-api/kube-object";
+import { JsonApiErrorParsed } from "../../../common/k8s-api/json-api";
+import type { ShowNotification } from "../../../renderer/components/notifications";
+import React from "react";
describe("cluster/namespaces - edit namespace from new tab", () => {
let builder: ApplicationBuilder;
let apiKubePatchMock: AsyncFnMock
;
let apiKubeGetMock: AsyncFnMock;
- let showSuccessNotificationMock: jest.Mock;
- let showErrorNotificationMock: jest.Mock;
+ let showSuccessNotificationMock: jest.MockedFunction;
+ let showErrorNotificationMock: jest.MockedFunction;
beforeEach(() => {
builder = getApplicationBuilder();
@@ -418,6 +421,57 @@ metadata:
).toBeInTheDocument();
});
});
+
+ describe("when saving failings with a JsonApiError", () => {
+ beforeEach(async () => {
+ await apiKubePatchMock.reject(new JsonApiErrorParsed(
+ {
+ kind: "Status",
+ apiVersion: "v1",
+ metadata: {},
+ status: "Failure",
+ message: "PodDisruptionBudget.policy \"frontend-pdb\" is invalid: spec.minAvailable: Invalid value: -10: must be greater than or equal to 0",
+ reason: "Invalid",
+ details: {
+ name: "frontend-pdb",
+ group: "policy",
+ kind: "PodDisruptionBudget",
+ causes: [
+ {
+ reason: "FieldValueInvalid",
+ message: "Invalid value: -10: must be greater than or equal to 0",
+ field: "spec.minAvailable",
+ },
+ ],
+ },
+ code: 422,
+ },
+ [
+ "PodDisruptionBudget.policy \"frontend-pdb\" is invalid: spec.minAvailable: Invalid value: -10: must be greater than or equal to 0",
+ ],
+ ));
+ });
+
+ it("renders", () => {
+ expect(rendered.baseElement).toMatchSnapshot();
+ });
+
+ it("does not close the dock tab", () => {
+ expect(
+ rendered.getByTestId("dock-tab-for-some-first-tab-id"),
+ ).toBeInTheDocument();
+ });
+
+ it("shows an error notification with a condensed message", () => {
+ expect(showErrorNotificationMock).toBeCalledWith(
+
+ {"Failed to save resource:"}
+ {" "}
+ {'PodDisruptionBudget.policy "frontend-pdb" is invalid: spec.minAvailable: Invalid value: -10: must be greater than or equal to 0'}
+
,
+ );
+ });
+ });
});
describe("when selecting to cancel", () => {