使用原先 ExceptionHandler 共享 ExceptionInfoHolder 的方式。

This commit is contained in:
2023-02-09 00:32:12 +08:00
parent 151a33cad4
commit d01db60309
7 changed files with 31 additions and 32 deletions

View File

@@ -7,15 +7,13 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler;
import xyz.zhouxy.plusone.exception.handler.ExceptionInfoHolderFactory;
import xyz.zhouxy.plusone.system.application.exception.AccountLoginException;
import xyz.zhouxy.plusone.util.RestfulResult;
@RestControllerAdvice
public class AccountLoginExceptionHandler extends BaseExceptionHandler {
protected AccountLoginExceptionHandler() {
super(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder());
public AccountLoginExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
super(exceptionInfoHolder);
}
@ExceptionHandler({ AccountLoginException.class })

View File

@@ -15,8 +15,6 @@ import cn.dev33.satoken.exception.SaTokenException;
import cn.dev33.satoken.exception.SameTokenInvalidException;
import lombok.extern.slf4j.Slf4j;
import xyz.zhouxy.plusone.exception.handler.BaseExceptionHandler;
import xyz.zhouxy.plusone.exception.handler.ExceptionInfoHolderFactory;
import xyz.zhouxy.plusone.util.RestfulResult;
/**
* Sa-Token 异常处理器
@@ -27,8 +25,9 @@ import xyz.zhouxy.plusone.util.RestfulResult;
@Slf4j
public class SaTokenExceptionHandler extends BaseExceptionHandler {
public SaTokenExceptionHandler() {
super(ExceptionInfoHolderFactory.newDefaultExceptionInfoHolder());
public SaTokenExceptionHandler(ExceptionInfoHolder exceptionInfoHolder) {
super(exceptionInfoHolder);
set(NotPermissionException.class, 4030103, "会话未能通过权限认证", HttpStatus.FORBIDDEN);
set(NotRoleException.class, 4030103, "会话未能通过角色认证", HttpStatus.FORBIDDEN);
set(DisableServiceException.class, 4030202, "账号指定服务已被封禁", HttpStatus.FORBIDDEN);