001package run.iget.framework.common.handler; 002 003import java.util.Objects; 004 005import javax.servlet.http.HttpServletRequest; 006 007import org.springframework.boot.web.servlet.error.ErrorController; 008import org.springframework.stereotype.Controller; 009import org.springframework.web.bind.annotation.RequestMapping; 010 011import run.iget.framework.common.enums.BaseResultEnum; 012import run.iget.framework.common.util.ExceptionThrowUtils; 013 014/** 015 * 代码千万行,注释第一行,注释不规范,迭代两行泪 016 * ---------------类描述----------------- 017 * 错误路径返回json对象 018 * ---------------类描述----------------- 019 * 020 * @author 大周 021 * @since 2021/7/15 23:14:00 022 */ 023@Controller 024public class ResponseErrorController implements ErrorController { 025 026 /** 027 * 默认出错的请求路径 028 */ 029 private static final String ERROR_PATH = "/error"; 030 031 /** 032 * 请求错误时访问的地址 033 */ 034 @RequestMapping(ERROR_PATH) 035 public void handleError(HttpServletRequest request) throws Exception { 036 Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); 037 ExceptionThrowUtils.ofTrue(Objects.equals(statusCode, 400), BaseResultEnum.ERROR_LOGIN); 038 ExceptionThrowUtils.of(BaseResultEnum.ERROR_PARAM); 039 } 040}