Files
chapter-organizer/WebApp/Components/Shared/Components/AppErrorBoundary.razor
T

54 lines
2.2 KiB
Plaintext

@using Microsoft.AspNetCore.Components.Web
<ErrorBoundary>
<ChildContent>
@ChildContent
</ChildContent>
<ErrorContent Context="ex">
@{
Logger.LogError(ex, "Error boundary triggered - Exception details: {Message}", ex.Message);
}
<MudContainer MaxWidth="MaxWidth.Medium" Class="mt-8">
<MudPaper Elevation="3" Class="pa-6">
<MudAlert Severity="Severity.Error" Variant="Variant.Filled">
<MudText Typo="Typo.h5" Class="mb-2">
<MudIcon Icon="@Icons.Material.Filled.Error" Class="mr-2" />
An Error Occurred
</MudText>
@if (ShowDetails)
{
<MudText Typo="Typo.body2" Class="mt-4">
<strong>Error:</strong> @ex.Message
</MudText>
<MudText Typo="Typo.caption" Class="mt-2">
<strong>Stack Trace:</strong>
<pre style="overflow-x: auto;">@ex.StackTrace</pre>
</MudText>
}
else
{
<MudText Typo="Typo.body2">
Something went wrong. Please try refreshing the page or contact support if the problem persists.
</MudText>
}
</MudAlert>
<MudButton Variant="Variant.Filled"
Color="Color.Primary"
Class="mt-4"
OnClick="@(() => Navigation.NavigateTo("/", forceLoad: true))">
Return to Home
</MudButton>
</MudPaper>
</MudContainer>
</ErrorContent>
</ErrorBoundary>
@code {
[Parameter] public RenderFragment? ChildContent { get; set; }
[Inject] private IWebHostEnvironment Environment { get; set; } = default!;
[Inject] private NavigationManager Navigation { get; set; } = default!;
[Inject] private ILogger<AppErrorBoundary> Logger { get; set; } = default!;
private bool ShowDetails => Environment.IsDevelopment();
}