1 package org.woehlke.bloodmoney.application; 2 3 import lombok.extern.slf4j.Slf4j; 4 import org.springframework.boot.web.servlet.error.ErrorController; 5 import org.springframework.http.HttpStatus; 6 import org.springframework.stereotype.Controller; 7 import org.springframework.ui.Model; 8 import org.springframework.web.bind.annotation.RequestMapping; 9 10 import javax.servlet.RequestDispatcher; 11 import javax.servlet.http.HttpServletRequest; 12 13 @Slf4j 14 @Controller 15 public class BloodMoneyErrorController implements ErrorController { 16 17 @RequestMapping("/fehler") 18 public String handleError(HttpServletRequest request, Model model) { 19 Exception exception = (Exception) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); 20 log.info("exceptionMessage: "+exception); 21 Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); 22 if (status != null) { 23 log.info("statusCode: "+status.toString()); 24 Integer statusCode = Integer.valueOf(status.toString()); 25 if(statusCode == HttpStatus.FORBIDDEN.value()) { 26 return "error/error-403"; 27 } 28 if(statusCode == HttpStatus.NOT_FOUND.value()) { 29 return "error/error-404"; 30 } 31 else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) { 32 return "error/error-500"; 33 } 34 } 35 model.addAttribute("exceptionMessage",exception); 36 return "error/error"; 37 } 38 39 @SuppressWarnings("deprecation") 40 @Override 41 public String getErrorPath() { 42 return "/fehler"; 43 } 44 }