package com.jttech.pfcs.conf;
|
|
import com.jttech.pfcs.vo.resp.ResponseVo;
|
import org.slf4j.Logger;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
/**
|
* 全域异常处理
|
* @author wanghc
|
* @version 1.0.0
|
* @date 2023-03-09
|
*/
|
@ControllerAdvice
|
public class GlobalExceptionHandler {
|
|
@ResponseBody
|
@ExceptionHandler(Exception.class)
|
public ResponseVo exceptionHandler(HttpServletRequest request, Exception exception) {
|
String errMsg = StringUtils.isEmpty(exception.getMessage()) ? "服务异常" : exception.getMessage();
|
//截取前面20个字符
|
errMsg = errMsg.substring(0,Math.min(20, errMsg.length()));
|
return ResponseVo.fail(-999, errMsg);
|
}
|
}
|