mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-11-28 01:00:05 +08:00
update 优化 增加 rpc 异常拦截器
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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异常,请联系管理员确认");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user