Просмотр исходного кода

fix: 修改全局异常捕获处理类

ylc
weihongyang 2 лет назад
Родитель
Сommit
4fe4936dfd
1 измененных файлов: 37 добавлений и 12 удалений
  1. +37
    -12
      ym-admin/src/main/java/com/cnbm/admin/exception/YmExceptionHandler.java

ym-admin/src/main/java/com/cnbm/admin/exception/RenExceptionHandler.java → 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();

Загрузка…
Отмена
Сохранить