增加公共异常处理
parent
afbcb67d0d
commit
1c2c31fd08
|
@ -50,19 +50,20 @@ public class AuthServiceImpl implements AuthService {
|
||||||
|
|
||||||
if (userInfoResult.getCode() == Constants.ERROR){
|
if (userInfoResult.getCode() == Constants.ERROR){
|
||||||
log.info("用户登录失败:{}", userInfoResult.getMsg());
|
log.info("用户登录失败:{}", userInfoResult.getMsg());
|
||||||
return null;
|
throw new RuntimeException(
|
||||||
|
String.format("用户登录失败:[%s]", userInfoResult.getMsg())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
UserInfo userInfo = userInfoResult.getData();
|
UserInfo userInfo = userInfoResult.getData();
|
||||||
if (userInfo == null){
|
if (userInfo == null){
|
||||||
log.info("用户登录失败:{}", userInfoResult.getMsg());
|
log.info("用户登录失败:{}", userInfoResult.getMsg());
|
||||||
return null;
|
throw new RuntimeException("用户登录失败:[用户名或者密码不存在]");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!password.equals(userInfo.getPassword())){
|
if (!password.equals(userInfo.getPassword())){
|
||||||
log.info("用户登录失败:密码错误");
|
log.info("用户登录失败:密码错误");
|
||||||
return null;
|
throw new RuntimeException("用户登录失败:[用户名或者密码不存在]");
|
||||||
}
|
}
|
||||||
|
|
||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.muyu.common.config;
|
||||||
|
|
||||||
|
import com.muyu.common.result.Result;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: DongZeLiang
|
||||||
|
* @date: 2024/5/24
|
||||||
|
* @Description: 异常处理器
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class ExceptionHandler {
|
||||||
|
|
||||||
|
@org.springframework.web.bind.annotation.ExceptionHandler(value = RuntimeException.class)
|
||||||
|
public Result<String> runtimeExceptionHandler(RuntimeException e) {
|
||||||
|
log.error("程序请求异常:[{}]",e.getMessage(), e);
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,2 +1,3 @@
|
||||||
com.muyu.common.redis.configure.RedisConfig
|
com.muyu.common.redis.configure.RedisConfig
|
||||||
com.muyu.common.redis.service.RedisService
|
com.muyu.common.redis.service.RedisService
|
||||||
|
com.muyu.common.config.ExceptionHandler
|
||||||
|
|
Loading…
Reference in New Issue