Closed welkinxu closed 1 year ago
it is a good idea,hope you can create a pr for it!
it is a good idea,hope you can create a pr for it!
OK, I'd love to do this!
@chuailiwu hi,pr has been submitted, please review。https://github.com/sofastack/sofa-bolt/pull/319
现在调用端的处理AsyncUserProcessor回写异常的方式: Object rsp = (Object) client.invokeSync(addr, req, 3000); if(rsp instance of Exeception ) { // 异常处理 } else { // 正常响应处理 Response rsp1 = (Response) rsp; }
我们期望调用端可以再try-catch中处理异常,保持与服务端sync-processor同样的语义: try { Response rsp = (Respnse)client.invokeSync(addr, req, 3000); }catch(Exception e){ }
期望AsyncContext 可以新增sendException方法: public interface AsyncContext { void sendResponse(Object responseObject); void sendException(Exception ex); }
具体在RpcAsyncContext中的实现,可以参考如下代码,将业务异常包装为ExceptionResponse而不是普通正常响应的Response: