|
|
@@ -1,57 +1,57 @@
|
|
|
-package com.fdkankan.common.config;
|
|
|
-
|
|
|
-import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
|
|
|
-import com.alibaba.csp.sentinel.slots.block.BlockException;
|
|
|
-import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
|
|
|
-import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
|
|
|
-import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
|
|
|
-import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
|
|
|
-import com.alibaba.csp.sentinel.slots.system.SystemBlockException;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.fdkankan.common.response.ResultData;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.IOException;
|
|
|
-
|
|
|
-/**
|
|
|
- * <p>
|
|
|
- * sentinel统一异常处理
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @author dengsixing
|
|
|
- * @since 2022/1/26
|
|
|
- **/
|
|
|
-@Slf4j
|
|
|
-@Component
|
|
|
-public class SentinelUrlBlockHandler implements BlockExceptionHandler {
|
|
|
- @Override
|
|
|
- public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws IOException {
|
|
|
- String msg = null;
|
|
|
- if (e instanceof FlowException) {
|
|
|
- msg = "限流了";
|
|
|
- } else if (e instanceof DegradeException) {
|
|
|
- msg = "降级了";
|
|
|
- } else if (e instanceof ParamFlowException) {
|
|
|
- msg = "热点参数限流";
|
|
|
- } else if (e instanceof SystemBlockException) {
|
|
|
- msg = "系统规则(负载/...不满足要求)";
|
|
|
- } else if (e instanceof AuthorityException) {
|
|
|
- msg = "授权规则不通过";
|
|
|
- }
|
|
|
- // http状态码
|
|
|
- response.setStatus(500);
|
|
|
- response.setCharacterEncoding("utf-8");
|
|
|
- response.setHeader("Content-Type", "application/json;charset=utf-8");
|
|
|
- response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
|
|
-
|
|
|
- new ObjectMapper()
|
|
|
- .writeValue(
|
|
|
- response.getWriter(),
|
|
|
- ResultData.error(-1, msg)
|
|
|
- );
|
|
|
- }
|
|
|
-}
|
|
|
+//package com.fdkankan.common.config;
|
|
|
+//
|
|
|
+//import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
|
|
|
+//import com.alibaba.csp.sentinel.slots.block.BlockException;
|
|
|
+//import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
|
|
|
+//import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
|
|
|
+//import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
|
|
|
+//import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
|
|
|
+//import com.alibaba.csp.sentinel.slots.system.SystemBlockException;
|
|
|
+//import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+//import com.fdkankan.common.response.ResultData;
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
+//import org.springframework.http.MediaType;
|
|
|
+//import org.springframework.stereotype.Component;
|
|
|
+//
|
|
|
+//import javax.servlet.http.HttpServletRequest;
|
|
|
+//import javax.servlet.http.HttpServletResponse;
|
|
|
+//import java.io.IOException;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * <p>
|
|
|
+// * sentinel统一异常处理
|
|
|
+// * </p>
|
|
|
+// *
|
|
|
+// * @author dengsixing
|
|
|
+// * @since 2022/1/26
|
|
|
+// **/
|
|
|
+//@Slf4j
|
|
|
+//@Component
|
|
|
+//public class SentinelUrlBlockHandler implements BlockExceptionHandler {
|
|
|
+// @Override
|
|
|
+// public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws IOException {
|
|
|
+// String msg = null;
|
|
|
+// if (e instanceof FlowException) {
|
|
|
+// msg = "限流了";
|
|
|
+// } else if (e instanceof DegradeException) {
|
|
|
+// msg = "降级了";
|
|
|
+// } else if (e instanceof ParamFlowException) {
|
|
|
+// msg = "热点参数限流";
|
|
|
+// } else if (e instanceof SystemBlockException) {
|
|
|
+// msg = "系统规则(负载/...不满足要求)";
|
|
|
+// } else if (e instanceof AuthorityException) {
|
|
|
+// msg = "授权规则不通过";
|
|
|
+// }
|
|
|
+// // http状态码
|
|
|
+// response.setStatus(500);
|
|
|
+// response.setCharacterEncoding("utf-8");
|
|
|
+// response.setHeader("Content-Type", "application/json;charset=utf-8");
|
|
|
+// response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
|
|
+//
|
|
|
+// new ObjectMapper()
|
|
|
+// .writeValue(
|
|
|
+// response.getWriter(),
|
|
|
+// ResultData.error(-1, msg)
|
|
|
+// );
|
|
|
+// }
|
|
|
+//}
|