修改异常枚举名称

This commit is contained in:
TinyAnts 2023-03-23 09:50:41 +08:00
parent 57053cc0e6
commit a9549e23c9
10 changed files with 58 additions and 59 deletions

View File

@ -7,7 +7,7 @@ import com.mdd.common.aop.NotPower;
import com.mdd.common.aop.NotLogin;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.entity.system.SystemAuthAdmin;
import com.mdd.common.enums.HttpEnum;
import com.mdd.common.enums.ErrorEnum;
import com.mdd.common.exception.LoginException;
import com.mdd.common.mapper.system.SystemAuthAdminMapper;
import com.mdd.common.util.StringUtils;
@ -73,7 +73,7 @@ public class LikeAdminInterceptor implements HandlerInterceptor {
List<String> ignoreUrl = Arrays.asList("system:login", "system:logout");
if (request.getMethod().equals("POST") && !ignoreUrl.contains(auths)) {
String message = "演示环境不支持修改数据,请下载源码本地部署体验";
AjaxResult<Object> result = AjaxResult.failed(HttpEnum.NO_PERMISSION.getCode(), message);
AjaxResult<Object> result = AjaxResult.failed(ErrorEnum.NO_PERMISSION.getCode(), message);
response.getWriter().print(JSON.toJSONString(result));
return false;
}
@ -139,16 +139,16 @@ public class LikeAdminInterceptor implements HandlerInterceptor {
// 令牌校验
String token = StpUtil.getTokenValue();
if (StringUtils.isNull(token) || StringUtils.isBlank(token)) {
Integer errCode = HttpEnum.TOKEN_EMPTY.getCode();
String errMsg = HttpEnum.TOKEN_EMPTY.getMsg();
Integer errCode = ErrorEnum.TOKEN_EMPTY.getCode();
String errMsg = ErrorEnum.TOKEN_EMPTY.getMsg();
throw new LoginException(errCode, errMsg);
}
// 登录校验
Object id = StpUtil.getLoginId();
if (StringUtils.isNull(id)) {
Integer errCode = HttpEnum.TOKEN_INVALID.getCode();
String errMsg = HttpEnum.TOKEN_INVALID.getMsg();
Integer errCode = ErrorEnum.TOKEN_INVALID.getCode();
String errMsg = ErrorEnum.TOKEN_INVALID.getMsg();
throw new LoginException(errCode, errMsg);
}
@ -162,15 +162,15 @@ public class LikeAdminInterceptor implements HandlerInterceptor {
// 删除校验
if (StringUtils.isNull(adminUser)) {
Integer errCode = HttpEnum.TOKEN_INVALID.getCode();
String errMsg = HttpEnum.TOKEN_INVALID.getMsg();
Integer errCode = ErrorEnum.TOKEN_INVALID.getCode();
String errMsg = ErrorEnum.TOKEN_INVALID.getMsg();
throw new LoginException(errCode, errMsg);
}
// 禁用校验
if (adminUser.getIsDisable().equals(1)) {
Integer errCode = HttpEnum.LOGIN_DISABLE_ERROR.getCode();
String errMsg = HttpEnum.LOGIN_DISABLE_ERROR.getMsg();
Integer errCode = ErrorEnum.LOGIN_DISABLE_ERROR.getCode();
String errMsg = ErrorEnum.LOGIN_DISABLE_ERROR.getMsg();
throw new LoginException(errCode, errMsg);
}

View File

@ -3,7 +3,7 @@ package com.mdd.admin.config.stp;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.enums.HttpEnum;
import com.mdd.common.enums.ErrorEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
@ -26,7 +26,7 @@ public class StpInException {
@ResponseBody
public AjaxResult<Object> handleNotLoginException(NotLoginException e){
String msg = e.getMessage().startsWith("Token无效") ? "尚未登录,请先登录!" : e.getMessage();
return AjaxResult.failed(HttpEnum.TOKEN_INVALID.getCode(), msg);
return AjaxResult.failed(ErrorEnum.TOKEN_INVALID.getCode(), msg);
}
/**
@ -36,7 +36,7 @@ public class StpInException {
@ExceptionHandler(NotPermissionException.class)
@ResponseBody
public AjaxResult<Object> handleNotPermissionException(){
return AjaxResult.failed(HttpEnum.NO_PERMISSION.getCode(), HttpEnum.NO_PERMISSION.getMsg());
return AjaxResult.failed(ErrorEnum.NO_PERMISSION.getCode(), ErrorEnum.NO_PERMISSION.getMsg());
}
}

View File

@ -9,7 +9,7 @@ import com.mdd.admin.vo.system.SystemCaptchaVo;
import com.mdd.admin.vo.system.SystemLoginVo;
import com.mdd.common.entity.system.SystemAuthAdmin;
import com.mdd.common.entity.system.SystemLogLogin;
import com.mdd.common.enums.HttpEnum;
import com.mdd.common.enums.ErrorEnum;
import com.mdd.common.exception.LoginException;
import com.mdd.common.exception.OperateException;
import com.mdd.common.mapper.system.SystemAuthAdminMapper;
@ -101,7 +101,7 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
String code = CaptchaCache.get(loginsValidate.getUuid());
if (!loginsValidate.getCode().equals(code)) {
throw new LoginException(HttpEnum.CAPTCHA_ERROR.getCode(), HttpEnum.CAPTCHA_ERROR.getMsg());
throw new LoginException(ErrorEnum.CAPTCHA_ERROR.getCode(), ErrorEnum.CAPTCHA_ERROR.getMsg());
}
}
@ -110,20 +110,20 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
.last("limit 1"));
if (StringUtils.isNull(sysAdmin) || sysAdmin.getIsDelete().equals(1)) {
this.recordLoginLog(0, loginsValidate.getUsername(), HttpEnum.LOGIN_ACCOUNT_ERROR.getMsg());
throw new LoginException(HttpEnum.LOGIN_ACCOUNT_ERROR.getCode(), HttpEnum.LOGIN_ACCOUNT_ERROR.getMsg());
this.recordLoginLog(0, loginsValidate.getUsername(), ErrorEnum.LOGIN_ACCOUNT_ERROR.getMsg());
throw new LoginException(ErrorEnum.LOGIN_ACCOUNT_ERROR.getCode(), ErrorEnum.LOGIN_ACCOUNT_ERROR.getMsg());
}
if (sysAdmin.getIsDisable().equals(1)) {
this.recordLoginLog(sysAdmin.getId(), loginsValidate.getUsername(), HttpEnum.LOGIN_DISABLE_ERROR.getMsg());
throw new LoginException(HttpEnum.LOGIN_DISABLE_ERROR.getCode(), HttpEnum.LOGIN_DISABLE_ERROR.getMsg());
this.recordLoginLog(sysAdmin.getId(), loginsValidate.getUsername(), ErrorEnum.LOGIN_DISABLE_ERROR.getMsg());
throw new LoginException(ErrorEnum.LOGIN_DISABLE_ERROR.getCode(), ErrorEnum.LOGIN_DISABLE_ERROR.getMsg());
}
String newPWd = password + sysAdmin.getSalt();
String md5Pwd = ToolUtils.makeMd5(newPWd);
if (!md5Pwd.equals(sysAdmin.getPassword())) {
this.recordLoginLog(sysAdmin.getId(), loginsValidate.getUsername(), HttpEnum.LOGIN_ACCOUNT_ERROR.getMsg());
throw new LoginException(HttpEnum.LOGIN_ACCOUNT_ERROR.getCode(), HttpEnum.LOGIN_ACCOUNT_ERROR.getMsg());
this.recordLoginLog(sysAdmin.getId(), loginsValidate.getUsername(), ErrorEnum.LOGIN_ACCOUNT_ERROR.getMsg());
throw new LoginException(ErrorEnum.LOGIN_ACCOUNT_ERROR.getCode(), ErrorEnum.LOGIN_ACCOUNT_ERROR.getMsg());
}
try {

View File

@ -1,6 +1,6 @@
package com.mdd.common.core;
import com.mdd.common.enums.HttpEnum;
import com.mdd.common.enums.ErrorEnum;
import lombok.Data;
import java.util.ArrayList;
@ -41,7 +41,7 @@ public class AjaxResult<T> {
* @return AjaxResult
*/
public static AjaxResult<Object> success() {
return new AjaxResult<>(HttpEnum.SUCCESS.getCode(), HttpEnum.SUCCESS.getMsg(), new ArrayList<>());
return new AjaxResult<>(ErrorEnum.SUCCESS.getCode(), ErrorEnum.SUCCESS.getMsg(), new ArrayList<>());
}
/**
@ -52,7 +52,7 @@ public class AjaxResult<T> {
* @return AjaxResult
*/
public static AjaxResult<Object> success(Integer code) {
return new AjaxResult<>(code, HttpEnum.SUCCESS.getMsg(), new ArrayList<>());
return new AjaxResult<>(code, ErrorEnum.SUCCESS.getMsg(), new ArrayList<>());
}
/**
@ -63,7 +63,7 @@ public class AjaxResult<T> {
* @return AjaxResult
*/
public static AjaxResult<Object> success(String msg) {
return new AjaxResult<>(HttpEnum.SUCCESS.getCode(), msg, new ArrayList<>());
return new AjaxResult<>(ErrorEnum.SUCCESS.getCode(), msg, new ArrayList<>());
}
/**
@ -74,7 +74,7 @@ public class AjaxResult<T> {
* @return AjaxResult
*/
public static <T> AjaxResult<T> success(T data) {
return new AjaxResult<>(HttpEnum.SUCCESS.getCode(), HttpEnum.SUCCESS.getMsg(), data);
return new AjaxResult<>(ErrorEnum.SUCCESS.getCode(), ErrorEnum.SUCCESS.getMsg(), data);
}
/**
@ -98,7 +98,7 @@ public class AjaxResult<T> {
* @return AjaxResult
*/
public static <T> AjaxResult <T> success(String msg, T data) {
return new AjaxResult<>(HttpEnum.SUCCESS.getCode(), msg, data);
return new AjaxResult<>(ErrorEnum.SUCCESS.getCode(), msg, data);
}
/**
@ -122,7 +122,7 @@ public class AjaxResult<T> {
* @return AjaxResult
*/
public static AjaxResult<Object> failed(Integer code) {
return new AjaxResult<>(code, HttpEnum.FAILED.getMsg(), new ArrayList<>());
return new AjaxResult<>(code, ErrorEnum.FAILED.getMsg(), new ArrayList<>());
}
/**
@ -133,7 +133,7 @@ public class AjaxResult<T> {
* @return AjaxResult
*/
public static AjaxResult<Object> failed(String msg) {
return new AjaxResult<>(HttpEnum.FAILED.getCode(), msg, new ArrayList<>());
return new AjaxResult<>(ErrorEnum.FAILED.getCode(), msg, new ArrayList<>());
}
/**
@ -144,7 +144,7 @@ public class AjaxResult<T> {
* @return AjaxResult
*/
public static <T> AjaxResult<T> failed(T data) {
return new AjaxResult<T>(HttpEnum.FAILED.getCode(), HttpEnum.FAILED.getMsg(), data);
return new AjaxResult<T>(ErrorEnum.FAILED.getCode(), ErrorEnum.FAILED.getMsg(), data);
}
/**

View File

@ -1,6 +1,6 @@
package com.mdd.common.enums;
public enum HttpEnum {
public enum ErrorEnum {
SUCCESS(200, "成功"),
FAILED(300, "失败"),
@ -27,7 +27,7 @@ public enum HttpEnum {
*/
private final int code;
private final String msg;
HttpEnum(int code, String msg) {
ErrorEnum(int code, String msg) {
this.code = code;
this.msg = msg;
}

View File

@ -3,7 +3,7 @@ package com.mdd.common.exception;
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.mdd.common.config.GlobalConfig;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.enums.HttpEnum;
import com.mdd.common.enums.ErrorEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
@ -35,7 +35,7 @@ public class GlobalException {
e.printStackTrace();
}
log.error("系统异常 {}", e.getMessage());
return AjaxResult.failed(HttpEnum.SYSTEM_ERROR.getCode(), e.getMessage());
return AjaxResult.failed(ErrorEnum.SYSTEM_ERROR.getCode(), e.getMessage());
}
/**
@ -45,7 +45,7 @@ public class GlobalException {
@ExceptionHandler(NoHandlerFoundException.class)
@ResponseBody
public AjaxResult<Object> handleNoHandlerFoundException(NoHandlerFoundException e){
return AjaxResult.failed(HttpEnum.REQUEST_404_ERROR.getCode(), e.getMessage());
return AjaxResult.failed(ErrorEnum.REQUEST_404_ERROR.getCode(), e.getMessage());
}
/**
@ -68,7 +68,7 @@ public class GlobalException {
@ResponseBody
public AjaxResult<Object> handleBindException(BindException e) {
BindingResult bindingResult = e.getBindingResult();
Integer code = HttpEnum.PARAMS_VALID_ERROR.getCode();
Integer code = ErrorEnum.PARAMS_VALID_ERROR.getCode();
String msg = Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage();
return AjaxResult.failed(code, msg);
}
@ -80,7 +80,7 @@ public class GlobalException {
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseBody
public AjaxResult<Object> handlePathException(MissingServletRequestParameterException e) {
Integer code = HttpEnum.PARAMS_VALID_ERROR.getCode();
Integer code = ErrorEnum.PARAMS_VALID_ERROR.getCode();
String msg = Objects.requireNonNull(e.getMessage());
return AjaxResult.failed(code, msg);
}
@ -93,7 +93,7 @@ public class GlobalException {
@ResponseBody
public AjaxResult<Object> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
BindingResult bindingResult = e.getBindingResult();
Integer code = HttpEnum.PARAMS_VALID_ERROR.getCode();
Integer code = ErrorEnum.PARAMS_VALID_ERROR.getCode();
String msg = Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage();
return AjaxResult.failed(code, msg);
}
@ -105,7 +105,7 @@ public class GlobalException {
@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseBody
public AjaxResult<Object> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
Integer code = HttpEnum.PARAMS_TYPE_ERROR.getCode();
Integer code = ErrorEnum.PARAMS_TYPE_ERROR.getCode();
String msg = Objects.requireNonNull(e.getMessage());
return AjaxResult.failed(code, msg.split(";")[0]);
}
@ -117,7 +117,7 @@ public class GlobalException {
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseBody
public AjaxResult<Object> handleRequestMethodException(HttpRequestMethodNotSupportedException e) {
Integer code = HttpEnum.REQUEST_METHOD_ERROR.getCode();
Integer code = ErrorEnum.REQUEST_METHOD_ERROR.getCode();
String msg = Objects.requireNonNull(e.getMessage());
return AjaxResult.failed(code, msg);
}
@ -129,7 +129,7 @@ public class GlobalException {
@ExceptionHandler(IllegalArgumentException.class)
@ResponseBody
public AjaxResult<Object> handleIllegalArgumentException(IllegalArgumentException e) {
Integer code = HttpEnum.ASSERT_ARGUMENT_ERROR.getCode();
Integer code = ErrorEnum.ASSERT_ARGUMENT_ERROR.getCode();
String msg = Objects.requireNonNull(e.getMessage());
return AjaxResult.failed(code, msg);
}
@ -141,7 +141,7 @@ public class GlobalException {
@ExceptionHandler(MybatisPlusException.class)
@ResponseBody
public AjaxResult<Object> handleMybatisPlusException(MybatisPlusException e) {
Integer code = HttpEnum.ASSERT_MYBATIS_ERROR.getCode();
Integer code = ErrorEnum.ASSERT_MYBATIS_ERROR.getCode();
String msg = Objects.requireNonNull(e.getMessage());
return AjaxResult.failed(code, msg);
}

View File

@ -1,7 +1,6 @@
package com.mdd.common.exception;
import com.mdd.common.enums.HttpEnum;
import io.swagger.models.auth.In;
import com.mdd.common.enums.ErrorEnum;
/**
* 操作系统异常
@ -9,7 +8,7 @@ import io.swagger.models.auth.In;
public class OperateException extends BaseException {
public OperateException(String msg) {
super(HttpEnum.FAILED.getCode(), msg);
super(ErrorEnum.FAILED.getCode(), msg);
}
public OperateException(String msg, Integer errCode) {

View File

@ -1,6 +1,6 @@
package com.mdd.common.exception;
import com.mdd.common.enums.HttpEnum;
import com.mdd.common.enums.ErrorEnum;
/**
* 支付失败异常
@ -8,7 +8,7 @@ import com.mdd.common.enums.HttpEnum;
public class PaymentException extends BaseException {
public PaymentException(String msg) {
super(HttpEnum.PAYMENT_ERROR.getCode(), msg);
super(ErrorEnum.PAYMENT_ERROR.getCode(), msg);
}
public PaymentException(String msg, Integer errCode) {

View File

@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mdd.common.aop.NotLogin;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.entity.user.User;
import com.mdd.common.enums.HttpEnum;
import com.mdd.common.enums.ErrorEnum;
import com.mdd.common.exception.LoginException;
import com.mdd.common.mapper.user.UserMapper;
import com.mdd.common.util.StringUtils;
@ -140,16 +140,16 @@ public class LikeFrontInterceptor implements HandlerInterceptor {
// 令牌校验
String token = StpUtil.getTokenValue();
if (StringUtils.isNull(token) || StringUtils.isBlank(token)) {
Integer errCode = HttpEnum.TOKEN_EMPTY.getCode();
String errMsg = HttpEnum.TOKEN_EMPTY.getMsg();
Integer errCode = ErrorEnum.TOKEN_EMPTY.getCode();
String errMsg = ErrorEnum.TOKEN_EMPTY.getMsg();
throw new LoginException(errCode, errMsg);
}
// 登录校验
Object id = StpUtil.getLoginId();
if (StringUtils.isNull(id)) {
Integer errCode = HttpEnum.TOKEN_INVALID.getCode();
String errMsg = HttpEnum.TOKEN_INVALID.getMsg();
Integer errCode = ErrorEnum.TOKEN_INVALID.getCode();
String errMsg = ErrorEnum.TOKEN_INVALID.getMsg();
throw new LoginException(errCode, errMsg);
}
@ -163,15 +163,15 @@ public class LikeFrontInterceptor implements HandlerInterceptor {
// 删除校验
if (StringUtils.isNull(user)) {
Integer errCode = HttpEnum.TOKEN_INVALID.getCode();
String errMsg = HttpEnum.TOKEN_INVALID.getMsg();
Integer errCode = ErrorEnum.TOKEN_INVALID.getCode();
String errMsg = ErrorEnum.TOKEN_INVALID.getMsg();
throw new LoginException(errCode, errMsg);
}
// 禁用校验
if (user.getIsDisable().equals(1)) {
Integer errCode = HttpEnum.LOGIN_DISABLE_ERROR.getCode();
String errMsg = HttpEnum.LOGIN_DISABLE_ERROR.getMsg();
Integer errCode = ErrorEnum.LOGIN_DISABLE_ERROR.getCode();
String errMsg = ErrorEnum.LOGIN_DISABLE_ERROR.getMsg();
throw new LoginException(errCode, errMsg);
}

View File

@ -3,7 +3,7 @@ package com.mdd.front.config.stp;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.enums.HttpEnum;
import com.mdd.common.enums.ErrorEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
@ -26,7 +26,7 @@ public class StpInException {
@ResponseBody
public AjaxResult<Object> handleNotLoginException(NotLoginException e){
String msg = e.getMessage().startsWith("Token无效") ? "尚未登录,请先登录!" : e.getMessage();
return AjaxResult.failed(HttpEnum.TOKEN_INVALID.getCode(), msg);
return AjaxResult.failed(ErrorEnum.TOKEN_INVALID.getCode(), msg);
}
/**
@ -36,7 +36,7 @@ public class StpInException {
@ExceptionHandler(NotPermissionException.class)
@ResponseBody
public AjaxResult<Object> handleNotPermissionException(){
return AjaxResult.failed(HttpEnum.NO_PERMISSION.getCode(), HttpEnum.NO_PERMISSION.getMsg());
return AjaxResult.failed(ErrorEnum.NO_PERMISSION.getCode(), ErrorEnum.NO_PERMISSION.getMsg());
}
}