|
@@ -0,0 +1,25 @@
|
|
|
|
+package com.fdkankan.gateway.exception;
|
|
|
|
+
|
|
|
|
+import static org.springframework.web.reactive.function.BodyInserters.fromValue;
|
|
|
|
+
|
|
|
|
+import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
|
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
|
+import com.fdkankan.common.response.ResultData;
|
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
+import org.springframework.web.reactive.function.server.ServerResponse;
|
|
|
|
+import org.springframework.web.server.ServerWebExchange;
|
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Description: Sentinel异常处理类
|
|
|
|
+ */
|
|
|
|
+public class SentinelBlockRequestHandler implements BlockRequestHandler {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Mono<ServerResponse> handleRequest(ServerWebExchange exchange, Throwable t) {
|
|
|
|
+ return ServerResponse.status(HttpStatus.TOO_MANY_REQUESTS)
|
|
|
|
+ .contentType(MediaType.APPLICATION_JSON)
|
|
|
|
+ .body(fromValue(ResultData.error(ErrorCode.SYSTEM_BUSY)));
|
|
|
|
+ }
|
|
|
|
+}
|