From 812cf73cb76eeaed530a36c8e848354d7d9269dd Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Wed, 11 May 2022 17:50:30 +0200 Subject: [PATCH] Shell deletion exception handling Signed-off-by: Georg Pfuetzenreuter --- .../net/libertacasa/pubsh/web/SchedulerBean.java | 1 - .../net/libertacasa/pubsh/web/WebApplication.java | 14 +++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/libertacasa/pubsh/web/SchedulerBean.java b/src/main/java/net/libertacasa/pubsh/web/SchedulerBean.java index b68a14a..26408df 100644 --- a/src/main/java/net/libertacasa/pubsh/web/SchedulerBean.java +++ b/src/main/java/net/libertacasa/pubsh/web/SchedulerBean.java @@ -26,7 +26,6 @@ public class SchedulerBean { @Bean public static Task shellRemovalTask() { - return Tasks.oneTime("shell-removal") .execute((instance, ctx) -> { System.out.printf("Running container removal task - Instance: %s, ctx: %s\n", instance, ctx); diff --git a/src/main/java/net/libertacasa/pubsh/web/WebApplication.java b/src/main/java/net/libertacasa/pubsh/web/WebApplication.java index a22c390..55628fe 100644 --- a/src/main/java/net/libertacasa/pubsh/web/WebApplication.java +++ b/src/main/java/net/libertacasa/pubsh/web/WebApplication.java @@ -276,7 +276,19 @@ public class WebApplication { System.out.printf("Deletion triggered for ID %s by %s (%s)\n", id, userid, username); - Docker.deleteShell(username, id); + try { + Docker.deleteShell(username, id); + String returnmessage = "Ok, deleted the shell with container ID " + id; + redirectAttributes.addFlashAttribute("message", returnmessage); + } catch (com.github.dockerjava.api.exception.NotFoundException exception) { + String returnmessage = "Shell does not exist, maybe it already expired?"; + redirectAttributes.addFlashAttribute("message", returnmessage); + System.out.println(exception); + } catch (Exception exception) { + String returnmessage = "Error."; + redirectAttributes.addFlashAttribute("message", returnmessage); + System.out.println(exception); + } return("redirect:/portal"); }