From b5886a3a3ac32377eeac39a891bb0caa9df650db Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 12 Oct 2023 14:50:21 +0200 Subject: [PATCH] Not found now returns proper 404 status code --- .../ailef/dbadmin/external/controller/GlobalController.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/tech/ailef/dbadmin/external/controller/GlobalController.java b/src/main/java/tech/ailef/dbadmin/external/controller/GlobalController.java index 12b7855..bf267d5 100644 --- a/src/main/java/tech/ailef/dbadmin/external/controller/GlobalController.java +++ b/src/main/java/tech/ailef/dbadmin/external/controller/GlobalController.java @@ -22,12 +22,15 @@ package tech.ailef.dbadmin.external.controller; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ModelAttribute; import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import tech.ailef.dbadmin.external.DbAdmin; import tech.ailef.dbadmin.external.DbAdminProperties; import tech.ailef.dbadmin.external.exceptions.DbAdminNotFoundException; @@ -50,13 +53,14 @@ public class GlobalController { private DbAdmin dbAdmin; @ExceptionHandler(DbAdminNotFoundException.class) - public String handleNotFound(Exception e, Model model) { + public String handleNotFound(Exception e, Model model, HttpServletResponse response) { model.addAttribute("status", "404"); model.addAttribute("error", "Error"); model.addAttribute("message", e.getMessage()); model.addAttribute("dbadmin_userConf", userConf); model.addAttribute("dbadmin_baseUrl", getBaseUrl()); model.addAttribute("dbadmin_version", dbAdmin.getVersion()); + response.setStatus(404); return "other/error"; }