| | | 1 | | using ArturRios.Output; |
| | | 2 | | using Microsoft.AspNetCore.Http; |
| | | 3 | | |
| | | 4 | | namespace ArturRios.Util.WebApi.EndpointToggle; |
| | | 5 | | |
| | | 6 | | /// <summary>Exception thrown by <see cref="EndpointToggleAttribute"/> when a disabled endpoint is reached and its |
| | | 7 | | /// disabled behavior is configured as <c>OutputType.Exception</c>. Carries one or more messages describing why the |
| | | 8 | | /// endpoint is unavailable and the status code to answer with, letting it be handled by the exception pipeline (for |
| | | 9 | | /// example <see cref="Middleware.ExceptionMiddleware"/>, which honors <see cref="StatusCode"/>).</summary> |
| | | 10 | | public class EndpointDisabledException : CustomException |
| | | 11 | | { |
| | | 12 | | /// <summary>Initializes a new instance answered with 404 Not Found.</summary> |
| | | 13 | | /// <param name="messages">The messages describing why the endpoint is disabled.</param> |
| | 4 | 14 | | public EndpointDisabledException(string[] messages) : this(messages, StatusCodes.Status404NotFound) { } |
| | | 15 | | |
| | | 16 | | /// <summary>Initializes a new instance answered with <paramref name="statusCode"/>.</summary> |
| | | 17 | | /// <param name="messages">The messages describing why the endpoint is disabled.</param> |
| | | 18 | | /// <param name="statusCode">The HTTP status code the disabled endpoint should answer with.</param> |
| | 12 | 19 | | public EndpointDisabledException(string[] messages, int statusCode) : base(messages) => StatusCode = statusCode; |
| | | 20 | | |
| | | 21 | | /// <summary>The HTTP status code the disabled endpoint should answer with.</summary> |
| | 2 | 22 | | public int StatusCode { get; } |
| | | 23 | | } |