diff --git a/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/exception/PersistenceExceptionHandlerAdvice.java b/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/exception/PersistenceExceptionHandlerAdvice.java index 89052c0..eab55e0 100644 --- a/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/exception/PersistenceExceptionHandlerAdvice.java +++ b/opensabre-starter-persistence/src/main/java/io/github/opensabre/persistence/exception/PersistenceExceptionHandlerAdvice.java @@ -3,11 +3,13 @@ import io.github.opensabre.common.core.entity.vo.Result; import io.github.opensabre.common.core.exception.SystemErrorType; import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; import org.springframework.dao.DuplicateKeyException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @Slf4j +@Order(100) @RestControllerAdvice public class PersistenceExceptionHandlerAdvice { diff --git a/opensabre-starter-rpc/src/main/java/io/github/opensabre/rpc/sentinel/config/OpensabreSentinelConfig.java b/opensabre-starter-rpc/src/main/java/io/github/opensabre/rpc/sentinel/config/OpensabreSentinelConfig.java new file mode 100644 index 0000000..4a4cc3a --- /dev/null +++ b/opensabre-starter-rpc/src/main/java/io/github/opensabre/rpc/sentinel/config/OpensabreSentinelConfig.java @@ -0,0 +1,10 @@ +package io.github.opensabre.rpc.sentinel.config; + +import io.github.opensabre.rpc.sentinel.exception.SentinelExceptionHandlerAdvice; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.context.annotation.Import; + +@AutoConfiguration +@Import({SentinelExceptionHandlerAdvice.class}) +public class OpensabreSentinelConfig { +} \ No newline at end of file diff --git a/opensabre-starter-rpc/src/main/java/io/github/opensabre/rpc/sentinel/exception/SentinelExceptionHandlerAdvice.java b/opensabre-starter-rpc/src/main/java/io/github/opensabre/rpc/sentinel/exception/SentinelExceptionHandlerAdvice.java new file mode 100644 index 0000000..05fc958 --- /dev/null +++ b/opensabre-starter-rpc/src/main/java/io/github/opensabre/rpc/sentinel/exception/SentinelExceptionHandlerAdvice.java @@ -0,0 +1,59 @@ +package io.github.opensabre.rpc.sentinel.exception; + +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 io.github.opensabre.common.core.entity.vo.Result; +import io.github.opensabre.common.core.exception.SystemErrorType; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +/** + * + */ +@Slf4j +@RestControllerAdvice +@Order(100) +public class SentinelExceptionHandlerAdvice { + + @ExceptionHandler(BlockException.class) + public Result blockException(BlockException e) { + log.error("block exception:{}", e.getMessage()); + return Result.fail(SystemErrorType.SYSTEM_BUSY); + } + + @ExceptionHandler(FlowException.class) + public Result flowException(FlowException e) { + log.error("flow exception:{}", e.getMessage()); + return Result.fail(SystemErrorType.SYSTEM_BUSY); + } + + @ExceptionHandler(DegradeException.class) + public Result degradeException(DegradeException e) { + log.error("degrade exception:{}", e.getMessage()); + return Result.fail(SystemErrorType.SYSTEM_BUSY); + } + + @ExceptionHandler(ParamFlowException.class) + public Result paramFlowException(ParamFlowException e) { + log.error("param flow exception:{}", e.getMessage()); + return Result.fail(SystemErrorType.SYSTEM_BUSY); + } + + @ExceptionHandler(SystemBlockException.class) + public Result systemBlockException(SystemBlockException e) { + log.error("system block exception:{}", e.getMessage()); + return Result.fail(SystemErrorType.SYSTEM_BUSY); + } + + @ExceptionHandler(AuthorityException.class) + public Result authorityException(AuthorityException e) { + log.error("authority exception:{}", e.getMessage()); + return Result.fail(SystemErrorType.SYSTEM_BUSY); + } +} diff --git a/opensabre-starter-rpc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/opensabre-starter-rpc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index da64d14..04c4a8d 100644 --- a/opensabre-starter-rpc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/opensabre-starter-rpc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,2 +1,3 @@ io.github.opensabre.rpc.openfeign.config.OpensabreFeignConfig -io.github.opensabre.rpc.openfeign.config.OpensabreLoadBalancerConfig \ No newline at end of file +io.github.opensabre.rpc.openfeign.config.OpensabreLoadBalancerConfig +io.github.opensabre.rpc.sentinel.config.OpensabreSentinelConfig \ No newline at end of file diff --git a/opensabre-starter-rpc/src/main/resources/opensabre-rpc.yml b/opensabre-starter-rpc/src/main/resources/opensabre-rpc.yml index 7217033..eb27ec0 100644 --- a/opensabre-starter-rpc/src/main/resources/opensabre-rpc.yml +++ b/opensabre-starter-rpc/src/main/resources/opensabre-rpc.yml @@ -1,4 +1,6 @@ feign: + circuitbreaker: + enabled: true sentinel: enabled: true httpclient: @@ -14,7 +16,7 @@ feign: default: connectTimeout: 5000 readTimeout: 10000 - loggerLevel: full + loggerLevel: FULL spring: cloud: sentinel: diff --git a/opensabre-web/src/main/java/io/github/opensabre/common/web/exception/DefaultGlobalExceptionHandlerAdvice.java b/opensabre-web/src/main/java/io/github/opensabre/common/web/exception/DefaultGlobalExceptionHandlerAdvice.java index c44dc11..9fd2093 100644 --- a/opensabre-web/src/main/java/io/github/opensabre/common/web/exception/DefaultGlobalExceptionHandlerAdvice.java +++ b/opensabre-web/src/main/java/io/github/opensabre/common/web/exception/DefaultGlobalExceptionHandlerAdvice.java @@ -4,6 +4,7 @@ import io.github.opensabre.common.core.exception.BaseException; import io.github.opensabre.common.core.exception.SystemErrorType; import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; import org.springframework.http.HttpStatus; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.web.HttpRequestMethodNotSupportedException; @@ -18,6 +19,7 @@ * 默认全局异常处理类 */ @Slf4j +@Order @RestControllerAdvice public class DefaultGlobalExceptionHandlerAdvice {