Skip to content

Commit

Permalink
fix #723: not print detail error in rpc server when exception declare…
Browse files Browse the repository at this point in the history
…d in method
  • Loading branch information
sunnights committed Jul 10, 2018
1 parent 533845e commit c118231
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
/**
* @author maijunsheng
* @version 创建时间:2013-5-23
*
*/
@SpiMeta(name = "motan")
public class DefaultProvider<T> extends AbstractProvider<T> {
Expand All @@ -41,8 +40,8 @@ public DefaultProvider(T proxyImpl, URL url, Class<T> clz) {
}

@Override
public T getImpl(){
return proxyImpl;
public T getImpl() {
return proxyImpl;
}

@Override
Expand All @@ -69,8 +68,20 @@ public Response invoke(Request request) {
} else {
response.setException(new MotanBizException("provider call process error", e));
}
//服务发生错误时,显示详细日志
LoggerUtil.error("Exception caught when during method invocation. request:" + request.toString(), e);

// not print detail error when exception declared in method
boolean logException = true;
for (Class<?> clazz : method.getExceptionTypes()) {
if (e.getCause().getClass() == clazz) {
logException = false;
break;
}
}
if (logException) {
LoggerUtil.error("Exception caught when during method invocation. request:" + request.toString(), e);
} else {
LoggerUtil.info("Exception caught when during method invocation. request:" + request.toString());
}
} catch (Throwable t) {
// 如果服务发生Error,将Error转化为Exception,防止拖垮调用方
if (t.getCause() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

@MotanAsync
public interface MotanDemoService {
String hello(String name);
String hello(String name);

User rename(User user, String name);
User rename(User user, String name) throws NullPointerException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.weibo.motan.demo.service.MotanDemoService;
import com.weibo.motan.demo.service.model.User;

import java.util.Objects;

@MotanService(export = "demoMotan:8002")
public class MotanDemoServiceImpl implements MotanDemoService {

Expand All @@ -31,10 +33,7 @@ public String hello(String name) {

@Override
public User rename(User user, String name) {
if (user == null) {
System.out.println("user: null");
return null;
}
Objects.requireNonNull(user);
System.out.println(user.getId() + " rename " + user.getName() + " to " + name);
user.setName(name);
return user;
Expand Down

0 comments on commit c118231

Please # to comment.