Beispiel #1
0
        /// <summary>
        /// Resolve the specified exception to an end-user exception that will be thrown from the client.
        /// The resolved exception is normally a RpcException. Returns true when the resolved exception is changed.
        /// </summary>
        internal bool ResolveException(string summary, Exception ex, [NotNull] out Status?status, out Exception resolvedException)
        {
            if (ex is OperationCanceledException)
            {
                status = (CallTask.IsCompletedSuccessfully()) ? CallTask.Result : new Status(StatusCode.Cancelled, string.Empty);
                if (!Channel.ThrowOperationCanceledOnCancellation)
                {
                    resolvedException = CreateRpcException(status.Value);
                    return(true);
                }
            }
            else if (ex is RpcException rpcException)
            {
                status = rpcException.Status;

                // If trailers have been set, and the RpcException isn't using them, then
                // create new RpcException with trailers. Want to try and avoid this as
                // the exact stack location will be lost.
                //
                // Trailers could be set in another thread so copy to local variable.
                var trailers = Trailers;
                if (trailers != null && rpcException.Trailers != trailers)
                {
                    resolvedException = CreateRpcException(status.Value);
                    return(true);
                }
            }
            else
            {
                var s = GrpcProtocolHelpers.CreateStatusFromException(summary, ex);

                // The server could exceed the deadline and return a CANCELLED status before the
                // client's deadline timer is triggered. When CANCELLED is received check the
                // deadline against the clock and change status to DEADLINE_EXCEEDED if required.
                if (s.StatusCode == StatusCode.Cancelled)
                {
                    lock (this)
                    {
                        if (IsDeadlineExceededUnsynchronized())
                        {
                            s = new Status(StatusCode.DeadlineExceeded, s.Detail, s.DebugException);
                        }
                    }
                }

                status            = s;
                resolvedException = CreateRpcException(s);
                return(true);
            }

            resolvedException = ex;
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Resolve the specified exception to an end-user exception that will be thrown from the client.
        /// The resolved exception is normally a RpcException. Returns true when the resolved exception is changed.
        /// </summary>
        internal bool ResolveException(string summary, Exception ex, [NotNull] out Status?status, out Exception resolvedException)
        {
            if (ex is OperationCanceledException)
            {
                status = (CallTask.IsCompletedSuccessfully()) ? CallTask.Result : new Status(StatusCode.Cancelled, string.Empty);
                if (!Channel.ThrowOperationCanceledOnCancellation)
                {
                    resolvedException = CreateRpcException(status.Value);
                    return(true);
                }
            }
            else if (ex is RpcException rpcException)
            {
                status = rpcException.Status;

                // If trailers have been set, and the RpcException isn't using them, then
                // create new RpcException with trailers. Want to try and avoid this as
                // the exact stack location will be lost.
                //
                // Trailers could be set in another thread so copy to local variable.
                var trailers = Trailers;
                if (trailers != null && rpcException.Trailers != trailers)
                {
                    resolvedException = CreateRpcException(status.Value);
                    return(true);
                }
            }
            else
            {
                status            = GrpcProtocolHelpers.CreateStatusFromException(summary, ex);
                resolvedException = CreateRpcException(status.Value);
                return(true);
            }

            resolvedException = ex;
            return(false);
        }