Skip to content

Commit 040c600

Browse files
authored
feat: send notification in case of failure during delete/patch (#308)
Signed-off-by: Philippe Martin <[email protected]>
1 parent 60ba2b9 commit 040c600

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

packages/extension/src/manager/contexts-manager.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ class TestContextsManager extends ContextsManager {
208208
return super.stopMonitoring(contextName);
209209
}
210210

211-
public override handleStatus(status: V1Status): void {
212-
return super.handleStatus(status);
211+
public override handleStatus(status: V1Status, actionMsg: string): void {
212+
return super.handleStatus(status, actionMsg);
213213
}
214214

215215
public override getTextualObjectsList(objects: { kind: string; name: string; namespace?: string }[]): string {
@@ -1534,7 +1534,7 @@ test('deleteObject handler returns Status', async () => {
15341534
await manager.deleteObject('Resource4', 'resource-name', 'other-ns');
15351535
expect(window.showInformationMessage).toHaveBeenCalled();
15361536
expect(resource4DeleteObjectMock).toHaveBeenCalledWith(expect.anything(), 'resource-name', 'other-ns');
1537-
expect(manager.handleStatus).toHaveBeenCalledWith(status);
1537+
expect(manager.handleStatus).toHaveBeenCalledWith(status, 'deletion of Resource4 resource-name');
15381538
});
15391539

15401540
test('deleteObject handler throws status embedded in ApiException', async () => {
@@ -1553,7 +1553,7 @@ test('deleteObject handler throws status embedded in ApiException', async () =>
15531553
await manager.deleteObject('Resource4', 'resource-name', 'other-ns');
15541554
expect(window.showInformationMessage).toHaveBeenCalled();
15551555
expect(resource4DeleteObjectMock).toHaveBeenCalledWith(expect.anything(), 'resource-name', 'other-ns');
1556-
expect(manager.handleStatus).toHaveBeenCalledWith(status);
1556+
expect(manager.handleStatus).toHaveBeenCalledWith(status, 'deletion of Resource4 resource-name');
15571557
});
15581558

15591559
test('deleteObject handler throws a non-Status in ApiException', async () => {

packages/extension/src/manager/contexts-manager.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ export class ContextsManager {
498498
const ns = namespace ?? this.currentContext.getNamespace();
499499
try {
500500
const result = await handler.deleteObject(this.currentContext, name, ns);
501-
this.handleResult(result);
501+
this.handleResult(result, `deletion of ${kind} ${name}`);
502502
} catch (error: unknown) {
503-
this.handleApiException(error);
503+
this.handleApiException(error, `deletion of ${kind} ${name}`);
504504
}
505505
}
506506

@@ -534,14 +534,14 @@ export class ContextsManager {
534534
return handler.restartObject(this.currentContext, name, ns);
535535
}
536536

537-
private handleResult(result: KubernetesObject | V1Status): void {
537+
private handleResult(result: KubernetesObject | V1Status, actionMsg: string): void {
538538
if (this.isV1Status(result)) {
539-
this.handleStatus(result);
539+
this.handleStatus(result, actionMsg);
540540
}
541541
// Ignore if result is a KubernetesObject
542542
}
543543

544-
private handleApiException(error: unknown): void {
544+
private handleApiException(error: unknown, actionMsg: string): void {
545545
if (error instanceof ApiException) {
546546
const statusError = error as ApiException<string>;
547547
let status: unknown;
@@ -551,7 +551,7 @@ export class ContextsManager {
551551
throw error;
552552
}
553553
if (this.isV1Status(status)) {
554-
this.handleStatus(status);
554+
this.handleStatus(status, actionMsg);
555555
} else {
556556
throw error;
557557
}
@@ -570,9 +570,13 @@ export class ContextsManager {
570570
);
571571
}
572572

573-
protected handleStatus(status: V1Status): void {
574-
console.error('status', status);
575-
// TODO: https://github.com/podman-desktop/extension-kubernetes-dashboard/issues/103
573+
protected handleStatus(status: V1Status, actionMsg: string): void {
574+
window.showNotification({
575+
title: actionMsg,
576+
body: status.message,
577+
type: 'error',
578+
highlight: true,
579+
});
576580
}
577581

578582
async deleteObjects(objects: { kind: string; name: string; namespace?: string }[]): Promise<void> {
@@ -805,9 +809,9 @@ export class ContextsManager {
805809
undefined, // force
806810
PatchStrategy.StrategicMergePatch,
807811
);
808-
this.handleResult(result);
812+
this.handleResult(result, `patch of ${manifest.kind} ${manifest.metadata?.name}`);
809813
} catch (error: unknown) {
810-
this.handleApiException(error);
814+
this.handleApiException(error, `patch of ${manifest.kind} ${manifest.metadata?.name}`);
811815
}
812816
}
813817
}

0 commit comments

Comments
 (0)