Page 1 of 1

How to redirect all exception pages to Custom error page?

Posted: Thu Oct 02, 2014 9:46 am
by gowthamgutha
Whenever I get an exception, I am being shown the exception stack trace on my web page which I don't want it in Production environment. Hence, I would like to display a custom error page for any of such exceptions and simply write the exception to a log.

My question is, is there a way to redirect all the exception pages to a custom page at once? If so, how can I do it?

Thanks in advance. Hope you will reply as soon as possible.

Re: How to redirect all exception pages to Custom error page?

Posted: Thu Oct 02, 2014 10:26 am
by phillipuniverse
This is not something that Broadleaf would handle but is more a Spring MVC/Servlet API question.

Re: How to redirect all exception pages to Custom error page?

Posted: Fri Oct 03, 2014 9:22 am
by prabhat.kataria
Take a look at viewtopic.php?f=15&t=3116
This worked for me but not sure if it's the correct way as it was not acknowledged by anybody working on BLC. Also I have raised a github issue at https://github.com/BroadleafCommerce/De ... issues/132 but sadly no response on that too...

Do tell me if you have a workaround. :)

Re: How to redirect all exception pages to Custom error page?

Posted: Fri Oct 03, 2014 11:35 am
by prabhat.kataria
I checked my code again and there is one more thing that you can do apart from the one I mentioned in my previous post.
Use below code to make a global exception handler. You can also take advantage of value attribute of ExceptionHandler annotation to configure specific exceptions.

Code: Select all

import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
class GlobalDefaultExceptionHandler {
    public static final String DEFAULT_ERROR_VIEW = "error/test";

    @ExceptionHandler(value = Exception.class)
    public String defaultrrorHandler(HttpServletRequest req, Exception e) throws Exception {
        return DEFAULT_ERROR_VIEW;
    }
}