I am trying to put interceptor to handle my custom authentication logic. So my prehandler will throw an exception if person in not logged in . I have my ErrorHandler controller added in script[/error] which gives json formatted error.
But when prehandler throws an exception it's all in html format, can i redirect my request to /error controller or if possible give my response in json format.
Script
public class AuthenticationInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
throw new Exception("HELLO");
}
}
Current Output
<title>Apache Tomcat/8.5.11 - Error report</title>
HTTP Status 500 - Request processing failed; nested exception is java.lang.Exception: HELLO
Expected Output
{"timestamp":1496584878547,"status":500,"error":"Found","message":"Hello"}
