Skip to content

Commit

Permalink
Updated unhandled exception handler in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
jschick04 committed Dec 4, 2024
1 parent d055721 commit 3e892b8
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 27 deletions.
27 changes: 15 additions & 12 deletions src/EventLogExpert/Main.razor
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<Fluxor.Blazor.Web.StoreInitializer />
<Router AppAssembly="@typeof(Main).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
<UnhandledExceptionHandler>
<Fluxor.Blazor.Web.StoreInitializer />

<Router AppAssembly="@typeof(Main).Assembly">
<Found Context="routeData">
<RouteView DefaultLayout="@typeof(MainLayout)" RouteData="@routeData" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</UnhandledExceptionHandler>
5 changes: 3 additions & 2 deletions src/EventLogExpert/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public static MauiApp CreateMauiApp()

builder.Services.AddMauiBlazorWebView();

if (Environment.GetCommandLineArgs().Contains("/EnableConsole", StringComparer.OrdinalIgnoreCase) ||
Environment.Version.CompareTo(new Version("9.0.0")) == 0)
#if RELEASE
if (Environment.GetCommandLineArgs().Contains("/EnableConsole", StringComparer.OrdinalIgnoreCase))
#endif
{
builder.Services.AddBlazorWebViewDeveloperTools();
}
Expand Down
10 changes: 5 additions & 5 deletions src/EventLogExpert/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@using EventLogExpert.Shared.Components
@using EventLogExpert.Components
@using EventLogExpert.Shared.Components
@using EventLogExpert.Shared.Components.Filters
@using EventLogExpert.Components
@inherits LayoutComponentBase

<div class="page" tabindex="0" @onkeyup="HandleKeyUp">
<div class="page" @onkeyup="HandleKeyUp" tabindex="0">
<SettingsModal />
<FilterCacheModal />
<FilterGroupModal />
Expand All @@ -12,10 +12,10 @@
<TableColumnMenu />
<ContextMenu />

<div class="display_layout">
<div class="page">
<FilterPane />
<EventTable />
<DetailsPane />
<StatusBar />
</div>
<StatusBar />
</div>
7 changes: 0 additions & 7 deletions src/EventLogExpert/Shared/MainLayout.razor.css

This file was deleted.

18 changes: 18 additions & 0 deletions src/EventLogExpert/Shared/UnhandledExceptionHandler.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@inherits ErrorBoundary

@if (CurrentException is null)
{
@ChildContent
}
else if (ErrorContent is not null)
{
@ErrorContent(CurrentException)
}
else
{
<div class="page">
@ChildContent

<div class="blazor-error-boundary"></div>
</div>
}
21 changes: 21 additions & 0 deletions src/EventLogExpert/Shared/UnhandledExceptionHandler.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// // Copyright (c) Microsoft Corporation.
// // Licensed under the MIT License.

using EventLogExpert.Eventing.Helpers;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.Logging;

namespace EventLogExpert.Shared;

public partial class UnhandledExceptionHandler : ErrorBoundary
{
[Inject] private ITraceLogger TraceLogger { get; set; } = null!;

protected override Task OnErrorAsync(Exception exception)
{
TraceLogger.Trace($"Unhandled exception in UI:\r\n{exception}", LogLevel.Critical);

return base.OnErrorAsync(exception);
}
}
1 change: 1 addition & 0 deletions src/EventLogExpert/wwwroot/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ html, body {
.page {
display: flex;
flex-direction: column;
height: 100%;
background-color: var(--background-dark);
color: var(--clr-lightblue);
}
Expand Down
2 changes: 1 addition & 1 deletion src/EventLogExpert/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<div class="status-bar-safe-area"></div>

<div id="app">Loading...</div>
<div id="app" style="height: 100%">Loading...</div>

<div id="blazor-error-ui">
An unhandled error has occurred.
Expand Down

0 comments on commit 3e892b8

Please sign in to comment.