修复系统异常时返回的响应是404的问题
This commit is contained in:
parent
f92ac3be80
commit
f859141de8
|
|
@ -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<ResultVO<String>> handleJeecgBootException(NflgBusinessException e) {
|
||||
public ResultVO<String> 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<ResultVO<String>> handlerNoFoundException(NoHandlerFoundException e) {
|
||||
public ResultVO<String> 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<ResultVO<String>> handleDuplicateKeyException(DuplicateKeyException e) {
|
||||
public ResultVO<String> handleDuplicateKeyException(DuplicateKeyException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
//return ResultVO.error("已存在该记录,请勿重复操作");
|
||||
return errorResult("已存在该记录,请勿重复操作");
|
||||
return ResultVO.error("已存在该记录,请勿重复操作");
|
||||
}
|
||||
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public ResponseEntity<ResultVO<String>> handleException(Exception e) {
|
||||
public ResultVO<String> 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<ResultVO<String>> HttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
|
||||
public ResultVO<String> 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<ResultVO<String>> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) {
|
||||
public ResultVO<String> 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<ResultVO<String>> handleDataIntegrityViolationException(DataIntegrityViolationException e) {
|
||||
public ResultVO<String> handleDataIntegrityViolationException(DataIntegrityViolationException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
// return ResultVO.error("字段太长,超出数据库字段的长度");
|
||||
return errorResult("字段太长,超出数据库字段的长度");
|
||||
return ResultVO.error("字段太长,超出数据库字段的长度");
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = SQLException.class)
|
||||
@ResponseBody
|
||||
public ResponseEntity<ResultVO<String>> handleSQLException(SQLException e) {
|
||||
public ResultVO<String> 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<ResultVO<String>> handleRuntimeExceptionException(RuntimeException e) {
|
||||
public ResultVO<String> 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<ResultVO<String>> handleDataAccessException(BadSqlGrammarException e) {
|
||||
public ResultVO<String> 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<ResultVO<String>> handleMethodArgumentException(MethodArgumentNotValidException e){
|
||||
public ResultVO<String> 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<ResultVO<String>> handleNullPointerException(NullPointerException ex) {
|
||||
@ResponseBody
|
||||
public ResultVO<String> handleNullPointerException(NullPointerException ex) {
|
||||
log.error(ex.getMessage(),ex);
|
||||
return errorResult(STATE.Error, "系统错误,请联系管理员:"+ex.getMessage()) ;
|
||||
return ResultVO.error(STATE.Error, "系统错误,请联系管理员") ;
|
||||
}
|
||||
|
||||
@ExceptionHandler(MissingServletRequestParameterException.class)
|
||||
public ResponseEntity<ResultVO<String>> handleMissingServletRequestParameterException(MissingServletRequestParameterException ex) {
|
||||
@ResponseBody
|
||||
public ResultVO<String> handleMissingServletRequestParameterException(MissingServletRequestParameterException ex) {
|
||||
log.error(ex.getMessage(),ex);
|
||||
return errorResult(STATE.ParamErr, ex.getParameterName()+"参数不能为空");
|
||||
}
|
||||
|
||||
private static ResponseEntity<ResultVO<String>> errorResult(String msg) {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(ResultVO.error(STATE.Error,msg));
|
||||
}
|
||||
private static ResponseEntity<ResultVO<String>> errorResult(STATE code,String msg) {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(ResultVO.error(code,msg));
|
||||
return ResultVO.error(STATE.ParamErr, ex.getParameterName()+"参数不能为空");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue