Ejemplo n.º 1
0
 protected override void ThrowOrIgnoreCore(ClientCallInterceptorContext context, ClientFaultDetail detail)
 {
     if (detail.Detail is ExceptionDetail error)
     {
         throw new ServerException(error, detail.OriginalError);
     }
 }
Ejemplo n.º 2
0
 public AsyncStreamReaderInterceptor(
     IAsyncStreamReader <TResponse> original,
     ClientCallInterceptorContext context,
     IClientCallInterceptor interceptor)
 {
     _original    = original;
     _context     = context;
     _interceptor = interceptor;
 }
Ejemplo n.º 3
0
 public void ThrowOrIgnore(ClientCallInterceptorContext context, ClientFaultDetail detail)
 {
     // if marker is UnexpectedErrorDetail
     if (detail.Detail is UnexpectedErrorDetail unexpectedErrorDetail)
     {
         // throw custom exception
         throw new UnexpectedErrorException(unexpectedErrorDetail);
     }
 }
Ejemplo n.º 4
0
 public void ThrowOrIgnore(ClientCallInterceptorContext context, ClientFaultDetail detail)
 {
     // if marker is ApplicationException
     if ((detail.Detail is string name) && name == "ApplicationException")
     {
         // throw custom exception
         throw new ApplicationException(detail.OriginalError.Status.Detail);
     }
 }
Ejemplo n.º 5
0
 public ClientStreamWriterInterceptor(
     IClientStreamWriter <TRequest> original,
     ClientCallInterceptorContext context,
     IClientCallInterceptor interceptor)
 {
     _original    = original;
     _context     = context;
     _interceptor = interceptor;
 }
Ejemplo n.º 6
0
 private async Task <TResponse> WaitAsyncUnaryCall <TResponse>(
     ClientCallInterceptorContext context,
     Task <TResponse> responseAsync)
     where TResponse : class
 {
     try
     {
         return(await responseAsync.ConfigureAwait(false));
     }
     catch (RpcException ex)
     {
         CallInterceptor.OnError(context, ex);
         throw;
     }
 }
Ejemplo n.º 7
0
        public void OnError(ClientCallInterceptorContext context, RpcException error)
        {
            object?detail = null;

            if (TryFindHeaders(error.Trailers, out var detailTypeName, out var detailContent))
            {
                var detailType = ResolveDetailType(detailTypeName);
                if (detailType != null)
                {
                    detail = MarshallerFactory.DeserializeHeader(detailType, detailContent);
                }
            }

            ErrorHandler.ThrowOrIgnore(context, new ClientFaultDetail(error, detail));
        }
Ejemplo n.º 8
0
        protected override void ThrowOrIgnoreCore(ClientCallInterceptorContext context, ClientFaultDetail detail)
        {
            // handle ApplicationExceptionFaultDetail
            if (detail.Detail is ApplicationExceptionFaultDetail appDetail)
            {
                throw new FaultException <ApplicationExceptionFaultDetail>(appDetail);
            }

            // handle InvalidOperationExceptionFaultDetail
            if (detail.Detail is InvalidOperationExceptionFaultDetail opDetail)
            {
                throw new FaultException <InvalidOperationExceptionFaultDetail>(opDetail);
            }

            // ignore other errors
        }
Ejemplo n.º 9
0
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
            TRequest request,
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var callContext = new ClientCallInterceptorContext(context.Options, context.Host, context.Method);

            var call = base.AsyncServerStreamingCall(request, context, continuation);

            return(new AsyncServerStreamingCall <TResponse>(
                       new AsyncStreamReaderInterceptor <TResponse>(call.ResponseStream, callContext, CallInterceptor),
                       call.ResponseHeadersAsync,
                       call.GetStatus,
                       call.GetTrailers,
                       call.Dispose));
        }
Ejemplo n.º 10
0
 public void BeforeEachTest()
 {
     _logger       = new LoggerMock();
     _errorHandler = new Mock <IClientErrorHandler>(MockBehavior.Strict);
     _context      = new ClientCallInterceptorContext(default, "host", new Mock <IMethod>(MockBehavior.Strict).Object);