add exception details if available
build / build (push) Successful in 42s Details

This commit is contained in:
Nick Seguin 2024-02-27 19:26:37 -06:00
parent ef898769ea
commit b03f320af3
Signed by: nseguin
GPG Key ID: 68C99FA84079021D
2 changed files with 17 additions and 28 deletions

View File

@ -1,5 +1,6 @@
@page "/Error"
@using System.Diagnostics
@using Microsoft.AspNetCore.Diagnostics
<PageTitle>Error</PageTitle>
@ -16,17 +17,33 @@
</p>
}
@if (ShowException)
{
<p class="text-slate mt-4 mb-4">
<h2 class="text-2xl font-bold">Exception</h2>
<pre class="text-md">
<code>@(Exception?.ToString())</code>
</pre>
</p>
}
@code{
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
[Inject]
private IHostEnvironment HostEnvironment { get; set; } = default!;
private Exception? Exception { get; set; }
private string? RequestId { get; set; }
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
private bool ShowException => Exception is not null && HostEnvironment.IsDevelopment();
protected override void OnInitialized()
{
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
Exception = HttpContext?.Features.Get<IExceptionHandlerFeature>()?.Error ?? new Exception("An error occurred while processing your request.");
}
}

View File

@ -2,32 +2,4 @@
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(SimpleLayout)"/>
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(SimpleLayout)">
<div class="fixed inset-y-0 right-0 left-[40rem] hidden lg:block xl:left-[50rem] z-0">
<svg
viewBox="0 0 1080 957"
fill="none"
aria-hidden="true"
class="absolute inset-0 h-full w-full"
preserveAspectRatio="xMinYMid slice">
<path fill="#2e3440" d="M0 0h1080v957H0z"/>
</svg>
</div>
<div class="px-4 py-10 sm:py-28 sm:px-6 lg:px-8 xl:py-32 xl:px-28">
<div class="mx-auto max-w-xl lg:mx-0">
<h1 class="mt-4 text-4xl md:text-5xl lg:text-6xl font-semibold text-[2rem] leading-10 tracking-tighter">Not Found</h1>
<p class="text-slate text-xl mt-4">
No page was found at this address. Please check the web address and try again.
</p>
<p class="text-blue-600 text-xl mt-4">
<a href="/" aria-label="Home" class="underline">Go to home page</a>
</p>
</div>
</div>
</LayoutView>
</NotFound>
</Router>