31e16fbc80
- keepalive: 30 s ping / 10 s timeout / Always, configurable via KeepAlivePingDelay/Timeout (CDN-004, D7) - GrpcStatusMapper shared by both transports: server Cancelled with a live token is no longer OperationCanceledException; NotFound/FailedPrecondition on session RPCs -> MxGatewaySessionException; MxGatewayException.GrpcStatusCode preserves the status (CDN-001, CDN-002) - Register/AddItem/AddItem2 raise MxGatewayMalformedReplyException on a payload-less reply (CDN-008) - MxGatewayEventStream.DisposeAsync waits for the in-flight read (CDN-003); session DisposeAsync is bounded to 5 s and swallows cancellation (CDN-005); owned handler + pinned CA disposed (CDN-006) - ResourceExhausted no longer retried (CDN-007) - CLI: batch reuses clients, stream/bench commands exempt from the 30 s timeout, OCE reported as an error with exit 1, --value redacted only for write-secured* and only as a whole token, bench backs off on failures (CDN-009, CDN-010, CDN-011)
54 lines
2.4 KiB
C#
54 lines
2.4 KiB
C#
using Grpc.Core;
|
|
|
|
namespace ZB.MOM.WW.MxGateway.Client;
|
|
|
|
/// <summary>
|
|
/// Maps a transport-level <see cref="RpcException"/> to the client's exception types. Shared by
|
|
/// the session and Galaxy Repository transports so the two cannot drift apart.
|
|
/// </summary>
|
|
internal static class GrpcStatusMapper
|
|
{
|
|
/// <summary>
|
|
/// Maps <paramref name="exception"/>. The original gRPC status stays reachable through
|
|
/// <see cref="MxGatewayException.GrpcStatusCode"/> and the inner exception.
|
|
/// </summary>
|
|
/// <param name="exception">The gRPC failure.</param>
|
|
/// <param name="cancellationToken">The caller's token.</param>
|
|
/// <param name="sessionScoped">
|
|
/// <see langword="true"/> for the session API, where <c>NotFound</c> / <c>FailedPrecondition</c>
|
|
/// mean the session is gone or not ready; the Galaxy Repository has no sessions.
|
|
/// </param>
|
|
/// <returns>The exception to throw.</returns>
|
|
public static Exception Map(RpcException exception, CancellationToken cancellationToken, bool sessionScoped)
|
|
{
|
|
// Only the caller's own cancellation is an OperationCanceledException. A Cancelled status
|
|
// with a live token was produced by the gateway (session closed or killed, gateway
|
|
// shutdown) and must not be swallowed by `catch (OperationCanceledException)` shutdown code.
|
|
if (cancellationToken.IsCancellationRequested)
|
|
{
|
|
return new OperationCanceledException(
|
|
exception.Status.Detail,
|
|
exception,
|
|
cancellationToken);
|
|
}
|
|
|
|
return exception.StatusCode switch
|
|
{
|
|
StatusCode.Unauthenticated => new MxGatewayAuthenticationException(
|
|
exception.Status.Detail,
|
|
innerException: exception),
|
|
StatusCode.PermissionDenied => new MxGatewayAuthorizationException(
|
|
exception.Status.Detail,
|
|
innerException: exception),
|
|
StatusCode.ResourceExhausted => new MxGatewayResourceExhaustedException(
|
|
exception.Status.Detail,
|
|
MxGatewayResourceExhaustedException.ReadReason(exception),
|
|
exception),
|
|
StatusCode.NotFound or StatusCode.FailedPrecondition when sessionScoped => new MxGatewaySessionException(
|
|
exception.Status.Detail,
|
|
innerException: exception),
|
|
_ => new MxGatewayException(exception.Status.Detail, exception),
|
|
};
|
|
}
|
|
}
|