| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | namespace IceRpc; |
| | 4 | |
|
| | 5 | | /// <summary>Represents an exception thrown while dispatching a request. It's encoded as a response with a status code |
| | 6 | | /// greater than <see cref="StatusCode.Ok" />.</summary> |
| | 7 | | public sealed class DispatchException : Exception |
| | 8 | | { |
| | 9 | | /// <summary>Gets or sets a value indicating whether the exception should be converted into a <see |
| | 10 | | /// cref="DispatchException" /> with status code <see cref="StatusCode.InternalError" /> when thrown from a |
| | 11 | | /// dispatch.</summary> |
| | 12 | | /// <value>When <see langword="true" />, this exception is converted into dispatch exception with status code <see |
| | 13 | | /// cref="StatusCode.InternalError" /> just before it's encoded. Defaults to <see langword="true" /> for an |
| | 14 | | /// exception decoded from an <see cref="IncomingResponse" />, and <see langword="false" /> for an exception created |
| | 15 | | /// by the application using a constructor of <see cref="DispatchException" />.</value> |
| 59 | 16 | | public bool ConvertToInternalError { get; set; } |
| | 17 | |
|
| | 18 | | /// <summary>Gets the status code.</summary> |
| | 19 | | /// <value>The <see cref="IceRpc.StatusCode" /> of this exception.</value> |
| 47 | 20 | | public StatusCode StatusCode { get; } |
| | 21 | |
|
| | 22 | | /// <summary>Constructs a new instance of <see cref="DispatchException" />.</summary> |
| | 23 | | /// <param name="statusCode">The status code of this exception. It must be greater than <see |
| | 24 | | /// cref="StatusCode.Ok" />.</param> |
| | 25 | | /// <param name="message">A message that describes the exception.</param> |
| | 26 | | /// <param name="innerException">The exception that is the cause of the current exception.</param> |
| | 27 | | /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="statusCode" /> is equal to <see |
| | 28 | | /// cref="StatusCode.Ok" />.</exception> |
| | 29 | | public DispatchException( |
| | 30 | | StatusCode statusCode, |
| | 31 | | string? message = null, |
| | 32 | | Exception? innerException = null) |
| 55 | 33 | | : base(message ?? $"The dispatch failed with status code {statusCode}.", innerException) => |
| 55 | 34 | | StatusCode = statusCode > StatusCode.Ok ? statusCode : |
| 55 | 35 | | throw new ArgumentOutOfRangeException( |
| 55 | 36 | | nameof(statusCode), |
| 55 | 37 | | $"The status code of a {nameof(DispatchException)} must be greater than {nameof(StatusCode.Ok)}."); |
| | 38 | | } |