I am having trouble handling different error codes with my application. I have followed this tutorial and it worked for a few hours. But after taking a break and getting back it seemed to have stopped working. Now every error (including 404 and 500 which I have seperate html files for) goes to the default error.html I have set application.properties as such:
management.endpoints.web.exposure.include=*
spring.datasource.url=jdbc:postgresql://192.168.0.38:5432/cms_database
spring.datasource.username=postgres
spring.datasource.password=password
server.error.whitelabel.enabled=false
server.error.path=/error
My ErrorController :
@Controller
public class MyErrorController implements ErrorController {
@RequestMapping("/error")
public String handleError(HttpServletRequest request) {
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
if (status != null) {
Integer statusCode = Integer.valueOf(status.toString());
if(statusCode == HttpStatus.NOT_FOUND.value()) {
return "error-404";
}
else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) {
return "error-500";
}
}
return "error";
}
@Override
public String getErrorPath() {
return null;
}
}
After trying to debug it seems that the controller stops working at the @RequestMapping which doesnt get invoked at all & the rest of the code.
Any tips or help is appreciated. Any other info you need I am happy to provide.
Nevermind, I noticed that in my other controller MainController I had a method written:
@GetMapping("/error")
public String showError() {
return "error";
}
whoops
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.