package com.shoppingcart.exception; import javassist.tools.rmi.ObjectNotFoundException; 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.ModelAndView; import javax.servlet.http.HttpServletRequest; import java.io.IOException; /** * Created by ysalmin on 22.07.2014. * Global exceptions handling. */ @ControllerAdvice public class GlobalExceptionHandler { private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); @ExceptionHandler(ObjectNotFoundException.class) public ModelAndView handleObjectNotFoundException(HttpServletRequest request, Exception ex){ ModelAndView modelAndView = new ModelAndView("error"); modelAndView.addObject("title", ex.getMessage().replace(" is not exported", "")); modelAndView.addObject("errorMsg", "error.msg.no.apps.found"); return modelAndView; } @ResponseStatus(value = HttpStatus.NOT_FOUND, reason="IOException occured") @ExceptionHandler(IOException.class) public void handleIOException(){ logger.error("IOException handler executed"); //returning 404 error code } }