| | |
| | | |
| | | import com.jttech.pfcs.vo.resp.ResponseVo; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.ControllerAdvice; |
| | | import org.springframework.web.bind.annotation.ExceptionHandler; |
| | |
| | | @ControllerAdvice |
| | | public class GlobalExceptionHandler { |
| | | |
| | | private Logger mLogger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | @ResponseBody |
| | | @ExceptionHandler(Exception.class) |
| | | public ResponseVo exceptionHandler(HttpServletRequest request, Exception exception) { |
| | | mLogger.error("请求发生异常 error={}", exception); |
| | | String errMsg = StringUtils.isEmpty(exception.getMessage()) ? "服务异常" : exception.getMessage(); |
| | | //截取前面20个字符 |
| | | errMsg = errMsg.substring(0,Math.min(20, errMsg.length())); |