diff --git a/eladmin-common/src/main/java/me/zhengjie/exception/handler/GlobalExceptionHandler.java b/eladmin-common/src/main/java/me/zhengjie/exception/handler/GlobalExceptionHandler.java index c6ea7daa..af166461 100644 --- a/eladmin-common/src/main/java/me/zhengjie/exception/handler/GlobalExceptionHandler.java +++ b/eladmin-common/src/main/java/me/zhengjie/exception/handler/GlobalExceptionHandler.java @@ -43,9 +43,7 @@ public class GlobalExceptionHandler { */ @ExceptionHandler(Throwable.class) public ResponseEntity handleException(Throwable e) { - // 打印堆栈信息 - log.error(ThrowableUtil.getStackTrace(e)); - return buildResponseEntity(ApiError.error(e.getMessage())); + return printErrorStackTrace(e); } /** @@ -74,9 +72,7 @@ public class GlobalExceptionHandler { */ @ExceptionHandler(value = EntityExistException.class) public ResponseEntity entityExistException(EntityExistException e) { - // 打印堆栈信息 - log.error(ThrowableUtil.getStackTrace(e)); - return buildResponseEntity(ApiError.error(e.getMessage())); + return printErrorStackTrace(e); } /** @@ -110,4 +106,13 @@ public class GlobalExceptionHandler { private ResponseEntity buildResponseEntity(ApiError apiError) { return new ResponseEntity<>(apiError, HttpStatus.valueOf(apiError.getStatus())); } + + /** + * 处理所有不可知的异常 + */ + public ResponseEntity printErrorStackTrace(Throwable e) { + // 打印堆栈信息 + log.error(ThrowableUtil.getStackTrace(e)); + return buildResponseEntity(ApiError.error(e.getMessage())); + } } diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/CloseUtil.java b/eladmin-common/src/main/java/me/zhengjie/utils/CloseUtil.java index 3a8d7a8b..93b1a1df 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/CloseUtil.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/CloseUtil.java @@ -26,16 +26,14 @@ import java.io.Closeable; public class CloseUtil { public static void close(Closeable closeable) { - if (null != closeable) { - try { - closeable.close(); - } catch (Exception e) { - // 静默关闭 - } - } + closeQuietly(closeable); } public static void close(AutoCloseable closeable) { + closeQuietly(closeable); + } + + public static void closeQuietly(Closeable closeable) { if (null != closeable) { try { closeable.close(); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java index 5aa0c45f..17a2dfc8 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java @@ -57,19 +57,19 @@ public class JwtUserDto implements UserDetails { @JSONField(serialize = false) @Override public boolean isAccountNonExpired() { - return true; + return isValid(); } @JSONField(serialize = false) @Override public boolean isAccountNonLocked() { - return true; + return isValid(); } @JSONField(serialize = false) @Override public boolean isCredentialsNonExpired() { - return true; + return isValid(); } @Override @@ -77,4 +77,8 @@ public class JwtUserDto implements UserDetails { public boolean isEnabled() { return user.getEnabled(); } + + public boolean isValid() { + return true; + } }