Shell deletion exception handling

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2022-05-11 17:50:30 +02:00
parent 1a4e969557
commit 812cf73cb7
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57
2 changed files with 13 additions and 2 deletions

View File

@ -26,7 +26,6 @@ public class SchedulerBean {
@Bean
public static Task<Void> shellRemovalTask() {
return Tasks.oneTime("shell-removal")
.execute((instance, ctx) -> {
System.out.printf("Running container removal task - Instance: %s, ctx: %s\n", instance, ctx);

View File

@ -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");
}