From 4fe4936dfdfd81a7d33d526cfe80ab4baffff768 Mon Sep 17 00:00:00 2001 From: weihongyang <1075331873@qq.com> Date: Wed, 22 Jun 2022 09:57:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7=E5=A4=84=E7=90=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...onHandler.java => YmExceptionHandler.java} | 49 ++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-) rename ym-admin/src/main/java/com/cnbm/admin/exception/{RenExceptionHandler.java => YmExceptionHandler.java} (62%) diff --git a/ym-admin/src/main/java/com/cnbm/admin/exception/RenExceptionHandler.java b/ym-admin/src/main/java/com/cnbm/admin/exception/YmExceptionHandler.java similarity index 62% rename from ym-admin/src/main/java/com/cnbm/admin/exception/RenExceptionHandler.java rename to ym-admin/src/main/java/com/cnbm/admin/exception/YmExceptionHandler.java index 9d5f48b..c33d554 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/exception/RenExceptionHandler.java +++ b/ym-admin/src/main/java/com/cnbm/admin/exception/YmExceptionHandler.java @@ -1,34 +1,30 @@ package com.cnbm.admin.exception; -import cn.hutool.core.map.MapUtil; -import com.cnbm.admin.entity.SysLogErrorEntity; import com.cnbm.admin.service.SysLogErrorService; import com.cnbm.common.exception.ErrorCode; -import com.cnbm.common.exception.ExceptionUtils; import com.cnbm.common.exception.RenException; -import com.cnbm.common.utils.HttpContextUtils; -import com.cnbm.common.utils.IpUtils; -import com.cnbm.common.utils.JsonUtils; import com.cnbm.common.utils.Result; +import lombok.extern.log4j.Log4j2; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DuplicateKeyException; -import org.springframework.http.HttpHeaders; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.DisabledException; +import org.springframework.security.authentication.InternalAuthenticationServiceException; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -import javax.servlet.http.HttpServletRequest; -import java.util.Map; - /** * @Author weihongyang * @Date 2022/6/10 2:05 PM * @Version 1.0 */ @RestControllerAdvice -public class RenExceptionHandler { - private static final Logger logger = LoggerFactory.getLogger(RenExceptionHandler.class); +@Log4j2 +public class YmExceptionHandler { + private static final Logger logger = LoggerFactory.getLogger(YmExceptionHandler.class); @Autowired private SysLogErrorService sysLogErrorService; @@ -44,6 +40,35 @@ public class RenExceptionHandler { return result; } + @ExceptionHandler(BadCredentialsException.class) + public Result handleBadCredentialsException(BadCredentialsException ex){ + Result result = new Result(); + result.error("密码错误"); + return result; + } + + @ExceptionHandler(UsernameNotFoundException.class) + public Result handleUsernameNotFoundException(UsernameNotFoundException ex){ + Result result = new Result(); + result.error(ex.getMessage()); + return result; + } + + @ExceptionHandler(InternalAuthenticationServiceException.class) + public Result handleInternalAuthenticationServiceException(InternalAuthenticationServiceException ex){ + Result result = new Result(); + result.error(ex.getMessage()); + return result; + } + + + @ExceptionHandler(LoginStatusException.class) + public Result handleLoginStatusException(LoginStatusException ex){ + Result result = new Result(); + result.error(ex.getMessage()); + return result; + } + @ExceptionHandler(DuplicateKeyException.class) public Result handleDuplicateKeyException(DuplicateKeyException ex){ Result result = new Result();