apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.34k stars 26.4k forks source link

org.apache.dubbo.rpc.filter.ExceptionFilter should't change the RuntimeException again #9677

Open shihaojun opened 2 years ago

shihaojun commented 2 years ago

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); }

zhaokjun commented 2 years ago

我也碰到了同样的问题,试了自定义一个exception filter,在onResponse里隐式传递参数,结果到了全局异常处理器里还是获取不到数据。

zhaokjun commented 2 years ago

https://github.com/apache/dubbo/issues/9342 看到这个了,试了一下,中文乱码依旧有,放弃triple协议了。还是老老实实用dubbo协议了,等坑填完了再说。dubbo协议全局异常处理器还是可以用的