Ejemplo n.º 1
0
        public static TResponse AlreadyExists <TResponse>(this ServerCallContext context, TResponse response, string?detail = null)
        {
            var logger = context.GetLogger();

            context.Status = new Status(StatusCode.AlreadyExists, detail ?? string.Empty);

            logger.Warning(detail);

            return(response);
        }
Ejemplo n.º 2
0
        public static TResponse Ok <TResponse>(this ServerCallContext context, TResponse response, string?detail = null)
        {
            var logger = context.GetLogger();

            context.Status = new Status(StatusCode.OK, detail ?? string.Empty);

            logger.Information(detail);

            return(response);
        }
Ejemplo n.º 3
0
        public static RpcException RpcException(this ServerCallContext context, Status status, Metadata?trailers = null)
        {
            var logger = context.GetLogger();

            var exception = trailers == null ? new RpcException(status) : new RpcException(status, trailers);

            switch (status.StatusCode)
            {
            case StatusCode.NotFound:
            case StatusCode.Cancelled:
            case StatusCode.Aborted:
            case StatusCode.Unauthenticated:
            case StatusCode.PermissionDenied:
            {
                logger.Warning(exception, status.Detail);

                break;
            }

            case StatusCode.InvalidArgument:
            case StatusCode.DeadlineExceeded:
            case StatusCode.FailedPrecondition:
            case StatusCode.OutOfRange:
            {
                logger.Error(exception, status.Detail);

                break;
            }

            case StatusCode.Unimplemented:
            case StatusCode.Internal:
            case StatusCode.Unavailable:
            case StatusCode.DataLoss:
            case StatusCode.Unknown:
            case StatusCode.ResourceExhausted:
            {
                logger.Fatal(exception, status.Detail);

                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException();
            }
            }

            return(exception);
        }