【发布时间】:2019-01-15 12:21:33
【问题描述】:
我想在 c# .net 核心中有一个用于 grpc 的拦截器,以检查所有请求凭据并记录所有 rpc 异常,但如果在没有 Await 关键字的情况下调用 Continuation 方法,则其异常不会在此级别引发。所以我等待拦截器继续捕获所有异常。 到目前为止一切正常,但我不知道它是否会在以后特别是在多个 cincurrent rpc 调用中引起任何问题?
public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TRequest request, ServerCallContext context, UnaryServerMethod<TRequest, TResponse> continuation)
{
try
{
CheckLogin(context);
var res = await continuation(request, context);
return res;
}
catch (RpcException ex)
{
_logger.LogError(ex, "RPC Error. UnaryServerHanler Error. Method : {method}", context.Method);
throw ex;
}
catch (Exception ex)
{
_logger.LogError(ex, "UnaryServerHanler Error. Method : {method}", context.Method);
throw ex;
}
}
【问题讨论】: