Using Exception handler i want to return new response and break the original handler response.if CustomException is thrown from filter.
i have tried below code but handler method is not called.
private boolean istest = true;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
KPICounterHelper.incrementRequestCounter(request);
if(istest) {
throw new CustomException("kd ex",55);
}
chain.doFilter(request, response);
KPICounterHelper.incrementResponseCounter(request);
}
//this is handler code
@RestControllerAdvice
public class ExceptionHandler extends ResponseEntityExceptionHandler{
@org.springframework.web.bind.annotation.ExceptionHandler(value=
{CustomException.class})
public CustomException handleCustom() {
System.out.println("in handler");
return new CustomException("kd excccc", 565);
}
}
//application.properties
spring.mvc.throw-exception-if-no-handler-found=true
spring.resources.add-mappings=fals
i want to execute handler code and return response from there. and want to execute method code after chain.doFilter()