I have a class called GlobalExceptionHandler
that is annotated by ControllerAdvice
. It properly handle all NoHandlerFoundExceptions
. I added a new method to to handle InternalError
exceptions but it does not handle such exceptions; therefore, I am still receiving HTTP Status 500
.
Based on this link the exception class of 500 (Internal Server Error)
is ConversionNotSupportedException
.
I tried following codes but none of the catch Internal Server Error.
1
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler
@ResponseStatus(HttpStatus.NOT_FOUND)
public String handleExceptionNotFound(NoHandlerFoundException ex) {
System.err.println("not found");
return "redirect:/error";
}
@ExceptionHandler(ConversionNotSupportedException.class)
// @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String handleExceptionsInternalError(ConversionNotSupportedException ex) {
ex.printStackTrace();
System.err.println("internal error");
return "redirect:/error";
}
}
2
@ExceptionHandler(ConversionNotSupportedException.class)
public String handleExceptionsInternalError(HttpServletRequest req, ConversionNotSupportedException ex) {
3
@ExceptionHandler
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String handleExceptionsInternalError(ConversionNotSupportedException ex) {
Exception that I need to handle is as follows:
HTTP Status 500 - Could not resolve view with name 'user' in servlet with name 'myproject'
javax.servlet.ServletException: Could not resolve view with name 'user' in servlet with name 'myproject'
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1211)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)