目录

1. sentinel 1.7版本(含)一下

2. sentinel 1.8 

3. 一共有3中方法

第一种:在springboot项目中,直接使用统一异常处理    

4. 参考链接


1. sentinel 1.7版本(含)一下

https://cloud.tencent.com/developer/article/1645215

 

2. sentinel 1.8 

https://blog.csdn.net/u011684553/article/details/108789968

 

3. 一共有3中方法


sentinel异常处理优先级 :@SentinelResource中定义了 blockHandler 和 faidback 属性  > UrlBlockHandler 和  BlockExceptionHandler  > 统一异常处理

第一种:在springboot项目中,直接使用统一异常处理    

/**
     * 替换默认流控提示内容:Blocked by sentinel(flow limiting)
     * 流控规则异常处理
     * 如果 @SentinelResource中定义了 blockHandler 和 faidback 属性,则此处不会捕获,以为 blockHandler 和 failback的优先级最高。
     * 限流处理、法一
     */
    @ExceptionHandler({FlowException.class})
    public R handleRRException(FlowException e){
        logger.error(RespConstant.RESP_MSG_FLOW_LIMITING_EXCEPTION, e);
        return RespUtils.commonHandle(RespConstant.RESP_CODE_FLOW_LIMITING_EXCEPTION, RespConstant.RESP_MSG_FLOW_LIMITING_EXCEPTION);
    }

    /**
     * 服务降级异常处理
     */
    @ExceptionHandler({DegradeException.class})
    public R handleRRException(DegradeException e){
        logger.error(RespConstant.RESP_MSG_DEGRADE_EXCEPTION, e);
        return RespUtils.commonHandle(RespConstant.RESP_CODE_DEGRADE_EXCEPTION, RespConstant.RESP_MSG_DEGRADE_EXCEPTION);
    }

    /**
     * 处理流量控制异常处理
     */
    @ExceptionHandler({AuthorityException.class})
    public R handleRRException(AuthorityException e){
        logger.error(RespConstant.RESP_MSG_AUTHORITY_EXCEPTION, e);
        return RespUtils.commonHandle(RespConstant.RESP_CODE_AUTHORITY_EXCEPTION, RespConstant.RESP_MSG_AUTHORITY_EXCEPTION);
    }

    /**
     * 处理流量控制异常处理
     */
    @ExceptionHandler({ParamFlowException.class})
    public R handleRRException(ParamFlowException e){
        logger.error(RespConstant.RESP_MSG_PARAM_FLOW_EXCEPTION, e);
        return RespUtils.commonHandle(RespConstant.RESP_CODE_PARAM_FLOW_EXCEPTION, RespConstant.RESP_MSG_PARAM_FLOW_EXCEPTION);
    }

    /**
     * 处理流量控制异常处理
     */
    @ExceptionHandler({SystemBlockException.class})
    public R handleRRException(SystemBlockException e){
        logger.error(RespConstant.RESP_MSG_SYSTEM_BLOCK_EXCEPTION, e);
        return RespUtils.commonHandle(RespConstant.RESP_CODE_SYSTEM_BLOCK_EXCEPTION, RespConstant.RESP_MSG_SYSTEM_BLOCK_EXCEPTION);
    }


    
    
第2种和第3种


        参考这里
    https://cloud.tencent.com/developer/article/1645215    

 

4. 参考链接

    https://cloud.tencent.com/developer/article/1645215    

https://blog.csdn.net/u011684553/article/details/108789968

https://cloud.tencent.com/developer/article/1645215

更多推荐