Просмотр исходного кода

【编辑】全局异常优化处理

linfutong лет назад: 2
Родитель
Сommit
05d2ec402a

+ 8 - 5
zd-common/common-core/src/main/java/com/zd/common/core/exception/GlobalExceptionHandler.java

@@ -32,7 +32,7 @@ public class GlobalExceptionHandler {
     public AjaxResult handlePreAuthorizeException(PreAuthorizeException e, HttpServletRequest request) {
         String requestURI = request.getRequestURI();
         log.error("请求地址'{}',权限校验失败'{}'", requestURI, e.getMessage());
-        return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员");
+        return AjaxResult.error(HttpStatus.FORBIDDEN, "无操作权限,请联系管理员");
     }
 
     /**
@@ -63,7 +63,7 @@ public class GlobalExceptionHandler {
     public AjaxResult handleDuplicateKeyException(DuplicateKeyException e, HttpServletRequest request) {
         String requestURI = request.getRequestURI();
         log.error("请求地址'{}',发生主键重复异常.", requestURI, e);
-        return AjaxResult.error("存在重复数据,操作失败!");
+        return AjaxResult.error("数据重复,请修改后再操作!");
     }
 
     /**
@@ -73,7 +73,10 @@ public class GlobalExceptionHandler {
     public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) {
         String requestURI = request.getRequestURI();
         log.error("请求地址'{}',发生未知异常.", requestURI, e);
-        return AjaxResult.error(e.getMessage());
+        if (e.getCause() != null) {
+            return AjaxResult.error(e.getCause().toString());
+        }
+        return AjaxResult.error(e.toString());
     }
 
     /**
@@ -112,7 +115,7 @@ public class GlobalExceptionHandler {
     @ExceptionHandler(RedisSystemException.class)
     public Object handleRedisSystemException(RedisSystemException e) {
         log.error(e.getMessage(), e);
-        return AjaxResult.error("正在重新连接...请重试!");
+        return AjaxResult.error("正在重新连接,请再次尝试!");
     }
 
     /**
@@ -122,7 +125,7 @@ public class GlobalExceptionHandler {
     public Object MaxUploadSizeExceededExceptionHandler(MaxUploadSizeExceededException e) {
         log.error("MaxUploadSizeExceededException: "+ e);
         e.printStackTrace();
-        return AjaxResult.error("上传文件太大!");
+        return AjaxResult.error("上传文件过大,请压缩后再试!");
     }
 
     /**

+ 0 - 4
zd-modules/zd-algorithm/src/main/java/com/zd/alg/iot/vmp/vmanager/gb28181/alarm/AlarmInfoController.java

@@ -71,8 +71,6 @@ public class AlarmInfoController {
         if (StringUtils.isEmpty(alarmType)) alarmType = null;
         if (StringUtils.isEmpty(startTime)) startTime = null;
         if (StringUtils.isEmpty(endTime)) endTime = null;
-
-
         try {
             if (startTime != null)  format.parse(startTime);
             if (endTime != null)  format.parse(endTime);
@@ -129,6 +127,4 @@ public class AlarmInfoController {
         wvpResult.setData(count);
         return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
     }
-
-
 }

+ 2 - 5
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabSensorServiceImpl.java

@@ -147,7 +147,7 @@ public class LabSensorServiceImpl implements ILabSensorService {
         Object subjectStr=redisService.getCacheObject(getKey(GatewayNum));
         Long subId=null;
         if(null!=subjectStr && !"".equals(subjectStr) ){
-            logger.error("num:"+GatewayNum+"subjectStr:"+subjectStr);
+            //logger.error("num:"+GatewayNum+"subjectStr:"+subjectStr);
             subId=Long.parseLong(subjectStr.toString());
         }
 
@@ -204,7 +204,7 @@ public class LabSensorServiceImpl implements ILabSensorService {
             subId=aLong;
             redisService.setCacheObject(getKey(GatewayNum),aLong,5L, TimeUnit.MINUTES);
         }
-        logger.error("num:"+GatewayNum+"subId:"+subId);
+        //logger.error("num:"+GatewayNum+"subId:"+subId);
         return subId;
     }
 
@@ -218,9 +218,6 @@ public class LabSensorServiceImpl implements ILabSensorService {
     @Override
     public int updateLabSensor(LabSensor labSensor) {
         labSensor.setUpdateTime(DateUtils.getNowDate());
-
-
-
         LabSensor old = labSensorMapper.selectLabSensorById(labSensor.getId());
         int i = labSensorMapper.updateLabSensor(labSensor);
         if(i==1)