mirror of
https://gitee.com/dromara/sa-token.git
synced 2026-05-14 12:52:08 +08:00
重构异常状态码机制
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package cn.dev33.satoken.reactor.error;
|
||||
|
||||
/**
|
||||
* 定义 sa-token-reactor-spring-boot-starter 所有异常细分状态码
|
||||
*
|
||||
* @author kong
|
||||
* @since: 2022-10-30
|
||||
*/
|
||||
public interface SaReactorSpringBootErrorCode {
|
||||
|
||||
/** 对象转 JSON 字符串失败 */
|
||||
public static final int CODE_20203 = 20203;
|
||||
|
||||
/** JSON 字符串转 Map 失败 */
|
||||
public static final int CODE_20204 = 20204;
|
||||
|
||||
/** 默认的 Filter 异常处理函数 */
|
||||
public static final int CODE_20205 = 20205;
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import cn.dev33.satoken.filter.SaFilterAuthStrategy;
|
||||
import cn.dev33.satoken.filter.SaFilterErrorStrategy;
|
||||
import cn.dev33.satoken.reactor.context.SaReactorHolder;
|
||||
import cn.dev33.satoken.reactor.context.SaReactorSyncHolder;
|
||||
import cn.dev33.satoken.reactor.error.SaReactorSpringBootErrorCode;
|
||||
import cn.dev33.satoken.router.SaRouter;
|
||||
import cn.dev33.satoken.util.SaTokenConsts;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -108,7 +109,7 @@ public class SaReactorFilter implements WebFilter {
|
||||
* 异常处理函数:每次[认证函数]发生异常时执行此函数
|
||||
*/
|
||||
public SaFilterErrorStrategy error = e -> {
|
||||
throw new SaTokenException(e);
|
||||
throw new SaTokenException(e).setCode(SaReactorSpringBootErrorCode.CODE_20205);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import cn.dev33.satoken.exception.SaJsonConvertException;
|
||||
import cn.dev33.satoken.json.SaJsonTemplate;
|
||||
import cn.dev33.satoken.reactor.error.SaReactorSpringBootErrorCode;
|
||||
|
||||
/**
|
||||
* JSON 转换器, Jackson 版实现
|
||||
@@ -31,7 +32,7 @@ public class SaJsonTemplateForJackson implements SaJsonTemplate {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(obj);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new SaJsonConvertException(e);
|
||||
throw new SaJsonConvertException(e).setCode(SaReactorSpringBootErrorCode.CODE_20203);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ public class SaJsonTemplateForJackson implements SaJsonTemplate {
|
||||
Map<String, Object> map = objectMapper.readValue(jsonStr, Map.class);
|
||||
return map;
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new SaJsonConvertException(e);
|
||||
throw new SaJsonConvertException(e).setCode(SaReactorSpringBootErrorCode.CODE_20204);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user