package kr.xit.biz.mbl.web;

import java.util.*;

import org.springframework.boot.web.error.*;
import org.springframework.boot.web.servlet.error.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.*;
import org.springframework.web.servlet.*;

@Controller
public class CustomErrorController implements ErrorController {

    private final ErrorAttributes errorAttributes;

    public CustomErrorController(ErrorAttributes errorAttributes) {
        this.errorAttributes = errorAttributes;
    }

    @RequestMapping("/error")
    public ModelAndView handleError(WebRequest webRequest) {
        Map<String, Object> errors = errorAttributes.getErrorAttributes(webRequest, ErrorAttributeOptions.defaults());

        ModelAndView mav = new ModelAndView("/error");
        mav.addObject("timestamp", errors.get("timestamp"));
        mav.addObject("status", errors.get("status"));
        mav.addObject("error", errors.get("error"));
        mav.addObject("message", errors.get("message"));
        mav.addObject("path", errors.get("path"));

        return mav;
    }
}
