suggest ExceptionFilter should't change the RuntimeException again
// directly throw if it's checked exception
if (!(exception instanceof RuntimeException) && (exception instanceof Exception)) {
return;
}
//ellipsis some code
// otherwise, wrap with RuntimeException and throw back to the client
appResponse.setException(new RuntimeException(StringUtils.toString(exception)));
on this code it change the Exception
I don't know what purpose of change the Exception,especially when this Exception instanceof RuntimeException,It just wrap it again
If you want to send some message by Exception,a instanceof of RuntimeException is a good choice.
It don't need to declare on every method,but catch on the global exception handler
For example,if you use java proxy,it auto generate a class like that if you has no exception appears in the signature:
try {
super.h.invoke(this, m3, (Object[])null);
} catch (RuntimeException | Error var2) {
throw var2;
} catch (Throwable var3) {
throw new UndeclaredThrowableException(var3);
}
2条答案
按热度按时间vc6uscn91#
我也碰到了同样的问题,试了自定义一个exception filter,在onResponse里隐式传递参数,结果到了全局异常处理器里还是获取不到数据。
ki1q1bka2#
#9342
看到这个了,试了一下,中文乱码依旧有,放弃triple协议了。还是老老实实用dubbo协议了,等坑填完了再说。dubbo协议全局异常处理器还是可以用的