LANCommander/LANCommander.UI/Components/ErrorHandler.razor

75 lines
No EOL
2.5 KiB
Text

@using Microsoft.JSInterop
@inject IJSRuntime JS
@inject NavigationManager NavigationManager
<ErrorBoundary>
<ChildContent>
@ChildContent
</ChildContent>
<ErrorContent>
<Result Status="ResultStatus.Error"
Title="Launcher Crashed"
SubTitle="@RandomQuip"
Class="crash-error">
<Extra>
<Button Type="ButtonType.Primary" OnClick="@(() => NavigationManager.NavigateTo("/", true))">View Library</Button>
<Button OnClick="() => CopyError(context)">Copy Error</Button>
</Extra>
<ChildContent>
<code>
@context.Message
@context.StackTrace
</code>
</ChildContent>
</Result>
</ErrorContent>
</ErrorBoundary>
@code {
[Parameter] public RenderFragment ChildContent { get; set; }
string RandomQuip = "";
string[] CrashQuips = new[]
{
"You Died.",
"Snake? SNAAAAAAKE!",
"WASTED",
"Major fracture detected",
"The past is a gaping hole. You try to run from it, but the more you run, the deeper, the darker, the bigger it gets.",
"Your town center has been destroyed",
"Your forces are under attack!",
"You have lost the lead",
"Terrorists Win",
"War... War never changes.",
"You have died of dysentery",
"You have failed to restore the books. The Ages are lost.",
"Player was splattered by a demon",
"Sure, blame it on your ISP",
"Baba is no more",
"Guests are complaining they are lost",
"The darkness has overcome you",
"Subject: Gordon Freeman. Status: Terminated",
"Mission failed: You were spotted.",
"Critical damage! Eject, eject!",
"Your minions are unhappy. They are leaving.",
"The Empire has triumphed",
"Your quest has ended in failure",
"You have been eaten by a grue",
"You no mess with Lo Wang!",
"Sam was killed. Serious carnage ensues.",
"Damn, those alien bastards are gonna pay for shooting up my ride"
};
protected override async Task OnInitializedAsync()
{
var randIndex = new Random().Next(0, CrashQuips.Length - 1);
RandomQuip = CrashQuips[randIndex];
}
async Task CopyError(Exception ex)
{
await JS.InvokeVoidAsync("navigator.clipboard.writeText", ex.Message + "\n" + ex.StackTrace);
}
}