update 优化 增加 rpc 异常拦截器

This commit is contained in:
疯狂的狮子Li
2025-01-08 16:01:58 +08:00
parent 08e407b7f4
commit 72d3e3caa8
2 changed files with 37 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package org.dromara.common.dubbo.config;
import org.dromara.common.core.factory.YmlPropertySourceFactory;
import org.dromara.common.dubbo.handler.DubboExceptionHandler;
import org.dromara.common.dubbo.properties.DubboCustomProperties;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
@@ -23,4 +24,13 @@ public class DubboConfiguration {
public BeanFactoryPostProcessor customBeanFactoryPostProcessor() {
return new CustomBeanFactoryPostProcessor();
}
/**
* 异常处理器
*/
@Bean
public DubboExceptionHandler dubboExceptionHandler() {
return new DubboExceptionHandler();
}
}

View File

@@ -0,0 +1,27 @@
package org.dromara.common.dubbo.handler;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.rpc.RpcException;
import org.dromara.common.core.domain.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* Dubbo异常处理器
*
* @author Lion Li
*/
@Slf4j
@RestControllerAdvice
public class DubboExceptionHandler {
/**
* 主键或UNIQUE索引数据重复异常
*/
@ExceptionHandler(RpcException.class)
public R<Void> handleDubboException(RpcException e) {
log.error("RPC异常: {}", e.getMessage());
return R.fail("RPC异常请联系管理员确认");
}
}