package com.eactive.httpmockserver.common.exception;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice(annotations = Controller.class)
@Order(2)
public class PortalGlobalExceptionHandler {

    private final Logger log = LoggerFactory.getLogger(getClass());

    @ExceptionHandler(value = NotFoundException.class)
    public ModelAndView handleIllegalArgumentException(HttpServletRequest request, NotFoundException ex) {
        log.error(ex.getMessage());
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error");
        modelAndView.addObject("exception", ex);
        return modelAndView;
    }

    @ExceptionHandler(value = UserNotLoginException.class)
    public ModelAndView handleIllegalArgumentException(HttpServletRequest request, UserNotLoginException ex) {
        return new ModelAndView("redirect:/login");
    }

}
