|
|
|
@ -18,6 +18,7 @@ import cn.hutool.json.JSONUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
import vip.xiaonuo.common.exception.CommonException; |
|
|
|
|
import vip.xiaonuo.common.pojo.CommonResult; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
@ -43,19 +44,22 @@ public class GlobalErrorViewController {
|
|
|
|
|
CommonResult<String> commonResult = new CommonResult<>(404, "路径不存在", null); |
|
|
|
|
Object model = request.getAttribute("model"); |
|
|
|
|
if(ObjectUtil.isNotEmpty(model)) { |
|
|
|
|
JSONObject errorObj = JSONUtil.parseObj(model); |
|
|
|
|
Integer code = errorObj.getInt("code"); |
|
|
|
|
String msg = errorObj.getStr("msg"); |
|
|
|
|
if(ObjectUtil.isAllNotEmpty(code, msg)) { |
|
|
|
|
commonResult.setCode(code).setMsg(msg); |
|
|
|
|
} else if(ObjectUtil.isNotEmpty(msg)) { |
|
|
|
|
commonResult = CommonResult.error(msg); |
|
|
|
|
} else { |
|
|
|
|
commonResult = CommonResult.error(); |
|
|
|
|
} |
|
|
|
|
if(model instanceof Exception){ |
|
|
|
|
Exception e = (Exception) model; |
|
|
|
|
log.error(">>> 服务器未知异常,具体信息:", e); |
|
|
|
|
if(model instanceof CommonException) { |
|
|
|
|
JSONObject errorObj = JSONUtil.parseObj(model); |
|
|
|
|
Integer code = errorObj.getInt("code"); |
|
|
|
|
String msg = errorObj.getStr("msg"); |
|
|
|
|
if(ObjectUtil.isAllNotEmpty(code, msg)) { |
|
|
|
|
commonResult.setCode(code).setMsg(msg); |
|
|
|
|
} else if(ObjectUtil.isNotEmpty(msg)) { |
|
|
|
|
commonResult = CommonResult.error(msg); |
|
|
|
|
} else { |
|
|
|
|
commonResult = CommonResult.error(); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
commonResult = CommonResult.error(); |
|
|
|
|
log.error(">>> 服务器未知异常,具体信息:", (Exception) model); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return commonResult; |
|
|
|
|