본문 바로가기

카테고리 없음

Springboot CustomErrorController구현

@Controller
@RequiredArgsConstructor
@Slf4j
public class CustomErrorController implements ErrorController {
@Override
public String getErrorPath() {
return ERROR_PATH;
}
@RequestMapping(value = ERROR_PATH)
public String handleError(HttpServletRequest request, ModelMap model) throws InterruptedException {

Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
HttpStatus httpStatus = HttpStatus.valueOf(Integer.parseInt(status.toString()));

pageErrorlog(request);

model.addAttribute("상태코드", status.toString());
model.addAttribute("메세지", httpStatus.getReasonPhrase());
model.addAttribute("타임스템프", new Date());

return "/error/error";
}