35 lines
1.3 KiB
Java
35 lines
1.3 KiB
Java
package ru.ulstu.fc.config;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
import org.springframework.web.servlet.NoHandlerFoundException;
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
@ControllerAdvice
|
|
@ApiIgnore
|
|
class GlobalDefaultExceptionHandler {
|
|
private final static Logger LOG = LoggerFactory.getLogger(GlobalDefaultExceptionHandler.class);
|
|
public static final String DEFAULT_ERROR_VIEW = "error";
|
|
|
|
|
|
// @ExceptionHandler(value = Exception.class)
|
|
// public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) {
|
|
// LOG.warn(e.getMessage());
|
|
// ModelAndView mav = new ModelAndView();
|
|
// mav.addObject("exception", e);
|
|
// mav.addObject("url", req.getRequestURL());
|
|
// mav.setViewName(DEFAULT_ERROR_VIEW);
|
|
// return mav;
|
|
// }
|
|
|
|
@ExceptionHandler(NoHandlerFoundException.class)
|
|
@ResponseStatus(HttpStatus.NOT_FOUND)
|
|
public String handle(NoHandlerFoundException ex) {
|
|
LOG.warn(ex.getMessage());
|
|
return "DEFAULT_ERROR_VIEW";
|
|
}
|
|
} |