diff --git a/nflg_project_dev/nflg-boot-base/nflg-boot-core/src/main/java/com/nflg/product/base/core/exception/BaseGlobalExceptionHandle.java b/nflg_project_dev/nflg-boot-base/nflg-boot-core/src/main/java/com/nflg/product/base/core/exception/BaseGlobalExceptionHandle.java index 80b0fa39..8348eea3 100644 --- a/nflg_project_dev/nflg-boot-base/nflg-boot-core/src/main/java/com/nflg/product/base/core/exception/BaseGlobalExceptionHandle.java +++ b/nflg_project_dev/nflg-boot-base/nflg-boot-core/src/main/java/com/nflg/product/base/core/exception/BaseGlobalExceptionHandle.java @@ -5,8 +5,6 @@ import nflg.product.common.constant.STATE; import nflg.product.common.vo.ResultVO; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DuplicateKeyException; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; @@ -34,35 +32,35 @@ public class BaseGlobalExceptionHandle { */ @ExceptionHandler(value = NflgBusinessException.class) @ResponseBody - public ResponseEntity> handleJeecgBootException(NflgBusinessException e) { + public ResultVO handleJeecgBootException(NflgBusinessException e) { log.error(e.getMessage(), e); //return ResultVO.error(e.getState(), e.getMessage()); - return errorResult(e.getState(),e.getMessage()); + return ResultVO.error(e.getState(),e.getMessage()); } @ExceptionHandler(value = NoHandlerFoundException.class) @ResponseBody - public ResponseEntity> handlerNoFoundException(NoHandlerFoundException e) { + public ResultVO handlerNoFoundException(NoHandlerFoundException e) { log.error(e.getMessage(), e); //return ResultVO.error(404, "路径不存在,请检查路径是否正确"); - return errorResult(STATE.AddressNotFound,"路径不存在,请检查路径是否正确"); + return ResultVO.error(STATE.AddressNotFound,"路径不存在,请检查路径是否正确"); } @ExceptionHandler(value = DuplicateKeyException.class) @ResponseBody - public ResponseEntity> handleDuplicateKeyException(DuplicateKeyException e) { + public ResultVO handleDuplicateKeyException(DuplicateKeyException e) { log.error(e.getMessage(), e); //return ResultVO.error("已存在该记录,请勿重复操作"); - return errorResult("已存在该记录,请勿重复操作"); + return ResultVO.error("已存在该记录,请勿重复操作"); } @ExceptionHandler(value = Exception.class) @ResponseBody - public ResponseEntity> handleException(Exception e) { + public ResultVO handleException(Exception e) { log.error(e.getMessage(), e); //return ResultVO.error("操作失败,请联系系统管理员"); - return errorResult("操作失败,请联系系统管理员"); + return ResultVO.error("操作失败,请联系系统管理员"); } /** @@ -72,7 +70,7 @@ public class BaseGlobalExceptionHandle { */ @ExceptionHandler(value = HttpRequestMethodNotSupportedException.class) @ResponseBody - public ResponseEntity> HttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { + public ResultVO HttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { log.error(e.getMessage(), e); StringBuilder sb = new StringBuilder(); sb.append("不支持"); @@ -88,7 +86,7 @@ public class BaseGlobalExceptionHandle { } log.error(sb.toString(), e); //return ResultVO.error(STATE.PermissionDenied, "登录已过期,请重新登录"); - return errorResult(STATE.PermissionDenied,"不支持的请求方法:"+e.getMethod()); + return ResultVO.error(STATE.PermissionDenied,"不支持的请求方法:"+e.getMethod()); } /** @@ -96,69 +94,62 @@ public class BaseGlobalExceptionHandle { */ @ExceptionHandler(value = MaxUploadSizeExceededException.class) @ResponseBody - public ResponseEntity> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) { + public ResultVO handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) { log.error(e.getMessage(), e); //return ResultVO.error("文件大小超出10MB限制, 请压缩或降低文件质量! "); - return errorResult("文件大小超出10MB限制, 请压缩或降低文件质量! "); + return ResultVO.error("文件大小超出10MB限制, 请压缩或降低文件质量! "); } @ExceptionHandler(value = DataIntegrityViolationException.class) @ResponseBody - public ResponseEntity> handleDataIntegrityViolationException(DataIntegrityViolationException e) { + public ResultVO handleDataIntegrityViolationException(DataIntegrityViolationException e) { log.error(e.getMessage(), e); // return ResultVO.error("字段太长,超出数据库字段的长度"); - return errorResult("字段太长,超出数据库字段的长度"); + return ResultVO.error("字段太长,超出数据库字段的长度"); } @ExceptionHandler(value = SQLException.class) @ResponseBody - public ResponseEntity> handleSQLException(SQLException e) { + public ResultVO handleSQLException(SQLException e) { log.error(e.getMessage(),e); //return ResultVO.error("sql执行过程出现错误"); - return errorResult("sql执行过程出现错误"); + return ResultVO.error("sql执行过程出现错误"); } @ExceptionHandler(value = RuntimeException.class) @ResponseBody - public ResponseEntity> handleRuntimeExceptionException(RuntimeException e) { + public ResultVO handleRuntimeExceptionException(RuntimeException e) { log.error(e.getMessage(),e); //throw new NflgBusinessException(STATE.Error, "系统错误,请联系管理员"); - return errorResult("系统错误,请联系管理员"); + return ResultVO.error("系统错误,请联系管理员"); } - - @ExceptionHandler(value = BadSqlGrammarException.class) @ResponseBody - public ResponseEntity> handleDataAccessException(BadSqlGrammarException e) { + public ResultVO handleDataAccessException(BadSqlGrammarException e) { log.error(e.getMessage(),e); //throw new NflgBusinessException(STATE.Error, "sql 语法错误,系统错误,请联系管理员"); - return errorResult("sql 语法错误,系统错误,请联系管理员"); + return ResultVO.error("sql 语法错误,系统错误,请联系管理员"); } @ExceptionHandler(value = MethodArgumentNotValidException.class) @ResponseBody - public ResponseEntity> handleMethodArgumentException(MethodArgumentNotValidException e){ + public ResultVO handleMethodArgumentException(MethodArgumentNotValidException e){ log.error(e.getMessage(),e); - return errorResult(e.getBindingResult().getFieldError().getDefaultMessage()) ; + return ResultVO.error(e.getBindingResult().getFieldError().getDefaultMessage()) ; } @ExceptionHandler(NullPointerException.class) - public ResponseEntity> handleNullPointerException(NullPointerException ex) { + @ResponseBody + public ResultVO handleNullPointerException(NullPointerException ex) { log.error(ex.getMessage(),ex); - return errorResult(STATE.Error, "系统错误,请联系管理员:"+ex.getMessage()) ; + return ResultVO.error(STATE.Error, "系统错误,请联系管理员") ; } @ExceptionHandler(MissingServletRequestParameterException.class) - public ResponseEntity> handleMissingServletRequestParameterException(MissingServletRequestParameterException ex) { + @ResponseBody + public ResultVO handleMissingServletRequestParameterException(MissingServletRequestParameterException ex) { log.error(ex.getMessage(),ex); - return errorResult(STATE.ParamErr, ex.getParameterName()+"参数不能为空"); - } - - private static ResponseEntity> errorResult(String msg) { - return ResponseEntity.status(HttpStatus.OK).body(ResultVO.error(STATE.Error,msg)); - } - private static ResponseEntity> errorResult(STATE code,String msg) { - return ResponseEntity.status(HttpStatus.OK).body(ResultVO.error(code,msg)); + return ResultVO.error(STATE.ParamErr, ex.getParameterName()+"参数不能为空"); } }