mirror of
https://github.com/miawinter98/just-short-it.git
synced 2024-11-22 00:09:54 +00:00
changed: migrated error page to razor components
This commit is contained in:
parent
47e4849ac6
commit
2d19934a1b
27
Components/Pages/Error.razor
Normal file
27
Components/Pages/Error.razor
Normal file
|
@ -0,0 +1,27 @@
|
|||
@page "/error"
|
||||
@using System.Diagnostics
|
||||
|
||||
@inject IHttpContextAccessor HttpContextAccessor
|
||||
|
||||
<PageTitle>Error</PageTitle>
|
||||
|
||||
<section>
|
||||
<h1 class="text-3xl lg:text-5xl text-error mb-6">Unexpected Error</h1>
|
||||
<h2 class="text-xl lg:text-2xl text-secondary-content mb-3">
|
||||
An error occurred while processing your request
|
||||
</h2>
|
||||
|
||||
@if (ShowRequestId) {
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@RequestId</code>
|
||||
</p>
|
||||
}
|
||||
</section>
|
||||
|
||||
@code{
|
||||
public string? RequestId { get; set; }
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
protected override void OnInitialized() =>
|
||||
RequestId = Activity.Current?.Id ?? HttpContextAccessor.HttpContext?.TraceIdentifier;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
@page
|
||||
@model ErrorModel
|
||||
@{
|
||||
ViewData["Title"] = "Error";
|
||||
}
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<h1 class="text-3xl lg:text-5xl text-error">Error.</h1>
|
||||
<h2 class="text-2xl lg:text-4xl text-secondary-content">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
</div>
|
|
@ -1,27 +0,0 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace JustShortIt.Pages
|
||||
{
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class ErrorModel : PageModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
private readonly ILogger<ErrorModel> _logger;
|
||||
|
||||
public ErrorModel(ILogger<ErrorModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -67,7 +67,7 @@
|
|||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment()) {
|
||||
app.UseExceptionHandler("/Error");
|
||||
app.UseExceptionHandler("/error", createScopeForErrors: true);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue