| | | 1 | | namespace ProjectTemplate.Web.Models; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// View model for error pages that exposes request and status information. |
| | | 5 | | /// </summary> |
| | | 6 | | public class ErrorViewModel |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// The unique request identifier, if available. May be null. |
| | | 10 | | /// </summary> |
| | 54 | 11 | | public string? RequestId { get; set; } |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// The HTTP status code associated with the error. |
| | | 15 | | /// </summary> |
| | 72 | 16 | | public int StatusCode { get; set; } |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Indicates whether a request identifier should be shown. |
| | | 20 | | /// </summary> |
| | 18 | 21 | | public bool ShowRequestId => !string.IsNullOrWhiteSpace(RequestId); |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// A short title describing the error derived from the <see cref="StatusCode"/>. |
| | | 25 | | /// </summary> |
| | 36 | 26 | | public string Title => StatusCode switch |
| | 36 | 27 | | { |
| | 16 | 28 | | StatusCodes.Status400BadRequest => "Bad Request", |
| | 8 | 29 | | StatusCodes.Status401Unauthorized => "Unauthorized", |
| | 8 | 30 | | StatusCodes.Status403Forbidden => "Forbidden", |
| | 4 | 31 | | StatusCodes.Status404NotFound => "Page Not Found", |
| | 0 | 32 | | StatusCodes.Status429TooManyRequests => "Too Many Requests", |
| | 0 | 33 | | _ => "Application Error" |
| | 36 | 34 | | }; |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// A user-friendly message describing the error derived from the <see cref="StatusCode"/>. |
| | | 38 | | /// </summary> |
| | 18 | 39 | | public string Message => StatusCode switch |
| | 18 | 40 | | { |
| | 8 | 41 | | StatusCodes.Status400BadRequest => "The request could not be processed.", |
| | 4 | 42 | | StatusCodes.Status401Unauthorized => "Authentication is required to access this resource.", |
| | 4 | 43 | | StatusCodes.Status403Forbidden => "You do not have permission to access this resource.", |
| | 2 | 44 | | StatusCodes.Status404NotFound => "The requested page could not be found.", |
| | 0 | 45 | | StatusCodes.Status429TooManyRequests => "Too many requests were received. Please try again later.", |
| | 0 | 46 | | _ => "An unexpected error occurred while processing the request." |
| | 18 | 47 | | }; |
| | | 48 | | } |