[frontend] Add ErrorBoundary based error display
This commit is contained in:
parent
ba0d9f64f7
commit
87bcb23be9
3 changed files with 118 additions and 17 deletions
|
@ -1,6 +1,8 @@
|
||||||
@using Iceshrimp.Frontend.Components
|
@using Iceshrimp.Frontend.Components
|
||||||
@using Microsoft.AspNetCore.Components.Authorization
|
@using Microsoft.AspNetCore.Components.Authorization
|
||||||
<Router AppAssembly="@typeof(App).Assembly">
|
<ErrorBoundary @ref=ErrorBoundary>
|
||||||
|
<ChildContent>
|
||||||
|
<Router AppAssembly="@typeof(App).Assembly">
|
||||||
<Found Context="routeData">
|
<Found Context="routeData">
|
||||||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
|
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
|
||||||
<NotAuthorized>
|
<NotAuthorized>
|
||||||
|
@ -16,4 +18,13 @@
|
||||||
<p role="alert">Page not found.</p>
|
<p role="alert">Page not found.</p>
|
||||||
</LayoutView>
|
</LayoutView>
|
||||||
</NotFound>
|
</NotFound>
|
||||||
</Router>
|
</Router>
|
||||||
|
</ChildContent>
|
||||||
|
<ErrorContent Context="Exception">
|
||||||
|
<ErrorUi Exception="Exception"></ErrorUi>
|
||||||
|
</ErrorContent>
|
||||||
|
</ErrorBoundary>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private ErrorBoundary? ErrorBoundary { get; set; }
|
||||||
|
}
|
49
Iceshrimp.Frontend/Components/ErrorUi.razor
Normal file
49
Iceshrimp.Frontend/Components/ErrorUi.razor
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
@using Iceshrimp.Frontend.Core.Services
|
||||||
|
@using Iceshrimp.Frontend.Localization
|
||||||
|
@using Microsoft.Extensions.Localization
|
||||||
|
@inject IStringLocalizer<Localization> Loc;
|
||||||
|
@inject NavigationManager Navigation;
|
||||||
|
@inject VersionService Version;
|
||||||
|
|
||||||
|
<div class="error-ui">
|
||||||
|
<h3>@Loc["Unhandled Exception has occured"]</h3>
|
||||||
|
<div class="body">
|
||||||
|
<div class="text">
|
||||||
|
<div>
|
||||||
|
@Loc["If this issue happens more than once, please join our support chat at: "]<a href="https://chat.iceshrimp.dev/">https://chat.iceshrimp.dev/</a><br/>
|
||||||
|
@Loc["Providing the below stack trace and version information will aid in debugging."]
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="stacktrace">
|
||||||
|
<code>@Exception.GetType(): @Exception.Message @Exception.StackTrace</code>
|
||||||
|
</div>
|
||||||
|
<div class="version">
|
||||||
|
<span class="name">Iceshrimp.NET</span>
|
||||||
|
<span class="value">
|
||||||
|
<code>@Version.Version</code>
|
||||||
|
</span>
|
||||||
|
<span class="name">Codename</span>
|
||||||
|
<span class="value">
|
||||||
|
<code>@Version.Codename</code>
|
||||||
|
</span>
|
||||||
|
@if (Version.CommitHash != null)
|
||||||
|
{
|
||||||
|
<span class="name">Commit</span>
|
||||||
|
<span class="value">
|
||||||
|
<code>@Version.CommitHash</code>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="btn" @onclick="Reload">@Loc["Reload Application"]</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter] [EditorRequired] public required Exception Exception { get; set; }
|
||||||
|
|
||||||
|
private void Reload()
|
||||||
|
{
|
||||||
|
Navigation.Refresh(true);
|
||||||
|
}
|
||||||
|
}
|
41
Iceshrimp.Frontend/Components/ErrorUi.razor.css
Normal file
41
Iceshrimp.Frontend/Components/ErrorUi.razor.css
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
.stacktrace {
|
||||||
|
margin-top: 1rem;
|
||||||
|
align-self: center;
|
||||||
|
max-width: 80vw;
|
||||||
|
max-height: 50vh;
|
||||||
|
overflow: scroll;
|
||||||
|
background-color: black;
|
||||||
|
border-radius: 1rem;
|
||||||
|
padding: 0.5rem;
|
||||||
|
user-select: all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version {
|
||||||
|
max-width: 80vw;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-ui {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
color: lightgray;
|
||||||
|
user-select: all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value {
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
max-width: 100vw;
|
||||||
|
overflow: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue