cn.acyou.leo.framework.commons.CustomErrorController Maven / Gradle / Ivy
package cn.acyou.leo.framework.commons;
import cn.acyou.leo.framework.constant.CommonErrorEnum;
import cn.acyou.leo.framework.model.Result;
import cn.acyou.leo.framework.util.BeanUtil;
import io.swagger.annotations.Api;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/**
* https://www.cnblogs.com/54chensongxia/archive/2020/11/20/14007696.html
* @author youfang
* @version [1.0.0, 2021/1/26]
**/
@Api(tags = "默认错误处理")
@Controller
@RequestMapping("${server.error.path:${error.path:/error}}")
public class CustomErrorController extends BasicErrorController {
public CustomErrorController(ServerProperties serverProperties) {
super(new DefaultErrorAttributes(), serverProperties.getError());
}
/**
* 覆盖Springboot 默认的JSON响应
*/
@Override
public ResponseEntity