1
0
Fork 0
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:
Mia Rose Winter 2023-11-18 16:41:38 +01:00
parent 47e4849ac6
commit 2d19934a1b
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
4 changed files with 28 additions and 45 deletions

View 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;
}

View file

@ -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>

View file

@ -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;
}
}
}

View file

@ -67,7 +67,7 @@
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) {
app.UseExceptionHandler("/Error");
app.UseExceptionHandler("/error", createScopeForErrors: true);
}