| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using System.Net.Quic; |
| | | 4 | | using System.Runtime.Versioning; |
| | | 5 | | |
| | | 6 | | namespace IceRpc.Transports.Quic.Internal; |
| | | 7 | | |
| | | 8 | | [SupportedOSPlatform("linux")] |
| | | 9 | | [SupportedOSPlatform("macos")] |
| | | 10 | | [SupportedOSPlatform("windows")] |
| | | 11 | | internal static class QuicExceptionExtensions |
| | | 12 | | { |
| | | 13 | | /// <summary>Converts a <see cref="QuicException"/> into an <see cref="IceRpcException"/>.</summary> |
| | | 14 | | internal static IceRpcException ToIceRpcException(this QuicException exception) => |
| | 39 | 15 | | exception.QuicError switch |
| | 39 | 16 | | { |
| | 39 | 17 | | QuicError.ConnectionAborted => |
| | 32 | 18 | | exception.ApplicationErrorCode is long applicationErrorCode ? |
| | 32 | 19 | | applicationErrorCode switch |
| | 32 | 20 | | { |
| | 32 | 21 | | (long)MultiplexedConnectionCloseError.NoError => |
| | 6 | 22 | | new IceRpcException(IceRpcError.ConnectionClosedByPeer), |
| | 32 | 23 | | (long)MultiplexedConnectionCloseError.Refused => |
| | 5 | 24 | | new IceRpcException(IceRpcError.ConnectionRefused), |
| | 32 | 25 | | (long)MultiplexedConnectionCloseError.ServerBusy => |
| | 6 | 26 | | new IceRpcException(IceRpcError.ServerBusy), |
| | 32 | 27 | | (long)MultiplexedConnectionCloseError.Aborted => |
| | 9 | 28 | | new IceRpcException( |
| | 9 | 29 | | IceRpcError.ConnectionAborted, |
| | 9 | 30 | | "The connection was aborted by the peer."), |
| | 6 | 31 | | _ => new IceRpcException( |
| | 6 | 32 | | IceRpcError.ConnectionAborted, |
| | 6 | 33 | | $"The connection was aborted by the peer with an unknown application error code: '{appli |
| | 32 | 34 | | } : |
| | 32 | 35 | | // An application error code should always be set with QuicError.ConnectionAborted. |
| | 32 | 36 | | new IceRpcException(IceRpcError.IceRpcError, exception), |
| | 0 | 37 | | QuicError.ConnectionRefused => new IceRpcException(IceRpcError.ConnectionRefused, exception), |
| | 0 | 38 | | QuicError.ConnectionTimeout => new IceRpcException(IceRpcError.ConnectionAborted, exception), |
| | 2 | 39 | | QuicError.ConnectionIdle => new IceRpcException(IceRpcError.ConnectionIdle, exception), |
| | 3 | 40 | | QuicError.OperationAborted => new IceRpcException(IceRpcError.OperationAborted, exception), |
| | 1 | 41 | | QuicError.AlpnInUse => new IceRpcException(IceRpcError.AddressInUse, exception), |
| | 39 | 42 | | QuicError.StreamAborted => |
| | 1 | 43 | | exception.ApplicationErrorCode is long applicationErrorCode ? |
| | 1 | 44 | | applicationErrorCode == 0 ? |
| | 1 | 45 | | new IceRpcException(IceRpcError.TruncatedData, exception) : |
| | 1 | 46 | | new IceRpcException( |
| | 1 | 47 | | IceRpcError.TruncatedData, |
| | 1 | 48 | | $"The stream was aborted by the peer with an unknown application error code: '{applicationEr |
| | 1 | 49 | | // An application error code should always be set with QuicError.StreamAborted. |
| | 1 | 50 | | new IceRpcException(IceRpcError.IceRpcError, exception), |
| | 0 | 51 | | _ => new IceRpcException(IceRpcError.IceRpcError, exception) |
| | 39 | 52 | | }; |
| | | 53 | | } |