|
@@ -1,6 +1,6 @@
|
|
|
package com.imed.costaccount.common.exception;
|
|
|
|
|
|
-import com.imed.costaccount.common.util.Result;
|
|
|
+import com.imed.costaccount.common.util.ErrorResult;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.shiro.authz.UnauthorizedException;
|
|
|
import org.springframework.dao.DataAccessException;
|
|
@@ -19,38 +19,38 @@ public class CostExceptionHandler {
|
|
|
|
|
|
|
|
|
@ExceptionHandler(value = CostException.class)
|
|
|
- public Result handlerEmosException(CostException e) {
|
|
|
+ public ErrorResult handlerEmosException(CostException e) {
|
|
|
e.printStackTrace();
|
|
|
log.info("GlobalExceptionHandler...");
|
|
|
log.info("错误代码:" + e.getMessage());
|
|
|
- return Result.errorMsg(500, e.getMessage());
|
|
|
+ return ErrorResult.errorMsg(500, e.getMessage());
|
|
|
}
|
|
|
|
|
|
// @ResponseStatus(value = HttpStatus.BAD_REQUEST)
|
|
|
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
|
|
- public Result handlerMethodArgumentNotValidException(MethodArgumentNotValidException e) {
|
|
|
+ public ErrorResult handlerMethodArgumentNotValidException(MethodArgumentNotValidException e) {
|
|
|
e.printStackTrace();
|
|
|
log.info("GlobalExceptionHandler...");
|
|
|
log.info("错误代码:" + e.getMessage());
|
|
|
- return Result.errorMsg(500, this.formatAllErrorMessages(e.getBindingResult().getAllErrors()));
|
|
|
+ return ErrorResult.errorMsg(500, this.formatAllErrorMessages(e.getBindingResult().getAllErrors()));
|
|
|
}
|
|
|
|
|
|
// @ResponseStatus(value = HttpStatus.UNAUTHORIZED)
|
|
|
@ExceptionHandler(value = UnauthorizedException.class)
|
|
|
- public Result handlerUnauthorizedException(UnauthorizedException e) {
|
|
|
+ public ErrorResult handlerUnauthorizedException(UnauthorizedException e) {
|
|
|
e.printStackTrace();
|
|
|
log.info("GlobalExceptionHandler...");
|
|
|
log.info("错误代码:" + e.getMessage());
|
|
|
- return Result.errorMsg(403,"您的权限不足,请联系管理员添加");
|
|
|
+ return ErrorResult.errorMsg(403,"您的权限不足,请联系管理员添加");
|
|
|
}
|
|
|
|
|
|
// @ResponseStatus(value = HttpStatus.BAD_REQUEST)
|
|
|
@ExceptionHandler(value = Exception.class)
|
|
|
- public Result handlerException(Exception e) {
|
|
|
+ public ErrorResult handlerException(Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.info("===============================GlobalExceptionHandler异常信息===============================");
|
|
|
log.info("错误代码:" + e.getLocalizedMessage());
|
|
|
- return Result.errorMsg("预期之外错误,请联系管理员~");
|
|
|
+ return ErrorResult.errorMsg(500,"预期之外错误,请联系管理员~");
|
|
|
}
|
|
|
|
|
|
private String formatAllErrorMessages(List<ObjectError> errors) {
|
|
@@ -69,9 +69,9 @@ public class CostExceptionHandler {
|
|
|
|
|
|
@ExceptionHandler(DataAccessException.class)
|
|
|
@ResponseBody
|
|
|
- public Result handleDataAccessException(DataAccessException e) {
|
|
|
+ public ErrorResult handleDataAccessException(DataAccessException e) {
|
|
|
log.error("数据库错误:{}", e.getMessage(), e);
|
|
|
- return Result.errorMsg("数据库错误");
|
|
|
+ return ErrorResult.errorMsg(500,"数据库错误");
|
|
|
|
|
|
}
|
|
|
}
|