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