commit init
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package com.cnbm.admin.exception;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.cnbm.admin.entity.SysLogErrorEntity;
|
||||
import com.cnbm.admin.service.SysLogErrorService;
|
||||
import com.cnbm.common.exception.ErrorCode;
|
||||
import com.cnbm.common.exception.ExceptionUtils;
|
||||
import com.cnbm.common.exception.RenException;
|
||||
import com.cnbm.common.utils.HttpContextUtils;
|
||||
import com.cnbm.common.utils.IpUtils;
|
||||
import com.cnbm.common.utils.JsonUtils;
|
||||
import com.cnbm.common.utils.Result;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author weihongyang
|
||||
* @Date 2022/6/10 2:05 PM
|
||||
* @Version 1.0
|
||||
*/
|
||||
//@RestControllerAdvice
|
||||
//public class RenExceptionHandler {
|
||||
// private static final Logger logger = LoggerFactory.getLogger(RenExceptionHandler.class);
|
||||
//
|
||||
// @Autowired
|
||||
// private SysLogErrorService sysLogErrorService;
|
||||
//
|
||||
// /**
|
||||
// * 处理自定义异常
|
||||
// */
|
||||
// @ExceptionHandler(RenException.class)
|
||||
// public Result handleRenException(RenException ex){
|
||||
// Result result = new Result();
|
||||
// result.error(ex.getCode(), ex.getMsg());
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// @ExceptionHandler(DuplicateKeyException.class)
|
||||
// public Result handleDuplicateKeyException(DuplicateKeyException ex){
|
||||
// Result result = new Result();
|
||||
// result.error(ErrorCode.DB_RECORD_EXISTS);
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// @ExceptionHandler(Exception.class)
|
||||
// public Result handleException(Exception ex){
|
||||
// logger.error(ex.getMessage(), ex);
|
||||
//
|
||||
// saveLog(ex);
|
||||
//
|
||||
// return new Result().error();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 保存异常日志
|
||||
// */
|
||||
// private void saveLog(Exception ex){
|
||||
// SysLogErrorEntity log = new SysLogErrorEntity();
|
||||
//
|
||||
// //请求相关信息
|
||||
// HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
|
||||
// log.setIp(IpUtils.getIpAddr(request));
|
||||
// log.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT));
|
||||
// log.setRequestUri(request.getRequestURI());
|
||||
// log.setRequestMethod(request.getMethod());
|
||||
// Map<String, String> params = HttpContextUtils.getParameterMap(request);
|
||||
// if(MapUtil.isNotEmpty(params)){
|
||||
// log.setRequestParams(JsonUtils.toJsonString(params));
|
||||
// }
|
||||
//
|
||||
// //异常信息
|
||||
// log.setErrorInfo(ExceptionUtils.getErrorStackTrace(ex));
|
||||
//
|
||||
// //保存
|
||||
// sysLogErrorService.save(log);
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user