I have the following in my RequestErrorController.java class

@Controller
public class RequestErrorController implements ErrorController {

    private static final Logger log = LoggerFactory.getLogger(RequestErrorController.class);
    @RequestMapping("/error")
    public String handleError(HttpServletRequest request) {
        Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);

        //log.error("Error 404 generated for this request ->"+ request.getRequestURI());
        if (status != null) {
            int statusCode = Integer.parseInt(status.toString());

            if(statusCode == HttpStatus.UNAUTHORIZED.value()) {
                return "error-401";
            }
            if(statusCode == HttpStatus.NOT_FOUND.value()) {
                return "error-404";
            }
            else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) {
                return "error-403";
            }
            else if(statusCode == HttpStatus.BAD_REQUEST.value()) {
                return "The request did not match any end-point. Please revise the request signature and parameters type. ";
            }
            // on va rajouter bad request vue que 500 est deja la
        }
        return "error";
    }

I have the following code

In my Http Interceptor:

  if(param.contains("web")){
               if(!webTerminalLinkParser(param)){
                   response.sendRedirect(ServerResourceURLLinkBuilder.getResourceURL("/error/403/403.html",false));
                   //request.setAttribute();
                   return false;
               }
            }

The problem is, I never get to see the custom 4xx pages.

Comment From: bclozel

Thanks for getting in touch, but it feels like this is a question that would be better suited to StackOverflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

In this case, I think you might misunderstand how HandlerInterceptor are involved in the request handling and how errors are processed with an error dispatch by the servlet container.

Instead you could also use the custom error pages support in Spring Boot instead, see https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.developing-web-applications.spring-mvc.error-handling.