-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...er-rpc/src/main/java/io/github/opensabre/rpc/sentinel/config/OpensabreSentinelConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
} |
59 changes: 59 additions & 0 deletions
59
.../main/java/io/github/opensabre/rpc/sentinel/exception/SentinelExceptionHandlerAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
io.github.opensabre.rpc.openfeign.config.OpensabreFeignConfig | ||
io.github.opensabre.rpc.openfeign.config.OpensabreLoadBalancerConfig | ||
io.github.opensabre.rpc.openfeign.config.OpensabreLoadBalancerConfig | ||
io.github.opensabre.rpc.sentinel.config.OpensabreSentinelConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters