refactor(auth): 优化认证服务异常处理逻辑

- 合并导入Spring Security认证相关类
- 增加对内部认证服务异常的捕获处理
- 保留业务异常的直接抛出
- 完善未知异常的日志记录,包含完整堆栈信息
- 调整设备响应DTO结构,增加字段分隔空行

fix(device): 调整设备响应对象结构

- 在设备响应DTO中添加ID字段上方空行以改善代码可读性
This commit is contained in:
Chaos
2025-11-23 21:59:59 +08:00
parent b2c6cfe90a
commit 4f0e0c163d
2 changed files with 9 additions and 7 deletions

View File

@@ -13,10 +13,7 @@ import cn.nopj.chaos_api.util.JwtTokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.DisabledException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.*;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
@@ -87,12 +84,16 @@ public class AuthServiceImpl implements AuthService {
res.setTokenHead(tokenHead);
return res;
}catch (BadCredentialsException e) {
}catch (BadCredentialsException | InternalAuthenticationServiceException e) {
throw new BizException(ErrorCode.USER_NOT_EXISTS_OR_PASSWORD_WRONG);
} catch (DisabledException e) {
throw new BizException(ErrorCode.USER_NOT_ENABLED);
} catch (Exception e) {
log.error("用户登录异常: {}", e.getMessage());
} catch (BizException e){
throw e;
}
catch (Exception e) {
log.error("用户登录异常",e);
throw new BizException(ErrorCode.SYSTEM_ERROR);
}
}