lundi 3 août 2015

How to catch http status errors by using @ControllerAdvice?

I have such contoller to handle exceptions:

@ControllerAdvice
public class GlobalErrorController {

public static final String DEFAULT_ERROR_VIEW = "errors/default";

@ExceptionHandler(Throwable.class)
public ModelAndView exception(Exception e) {

    ModelAndView mav = new ModelAndView(DEFAULT_ERROR_VIEW);
    mav.addObject("name", e.getClass().getSimpleName());
    mav.addObject("message", e.getMessage());

    return mav;
}

} 

Any exception are catched, but how can I catch 404 and others http status errors?

Aucun commentaire:

Enregistrer un commentaire