package com.icomsys.main_vm.biz.common.errorpage.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;

@Controller
@Slf4j
@RequiredArgsConstructor
public class ErrorPageController implements ErrorController {

    private final HttpServletRequest httpServletRequest;

    @GetMapping("/error")
    public String error(){
        log.info("error page init");
        Object status = httpServletRequest.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
        log.info("error status - {}", status.toString());

        if(status.equals("490")){
            return "adm/signin/signin";
        }
        if(status.toString().equals("491")){
            return "adm/signin/changePwd";
        }
//        ModelMap mm = new ModelMap();
//        ErrorResult er = new ErrorResult();
//        er.setCode(status.toString());
//        mm.addAttribute("errorResult", "aaa");
//        return "adm/common/error";
        return "adm/signin/signin";
    }
}







