From c3d7f7e36e62c51f7c3ac555e4903bde859bdff7 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Wed, 12 Apr 2023 16:52:09 +0200 Subject: [PATCH] Implemented new soft error boundary crash handler --- .../ErrorBoundaries/SoftErrorBoundary.razor | 29 ++++++- Moonlight/Shared/Layouts/MainLayout.razor | 82 +++++++++---------- Moonlight/Shared/Views/Test.razor | 29 +------ 3 files changed, 67 insertions(+), 73 deletions(-) diff --git a/Moonlight/Shared/Components/ErrorBoundaries/SoftErrorBoundary.razor b/Moonlight/Shared/Components/ErrorBoundaries/SoftErrorBoundary.razor index 7f56120..3d59dd7 100644 --- a/Moonlight/Shared/Components/ErrorBoundaries/SoftErrorBoundary.razor +++ b/Moonlight/Shared/Components/ErrorBoundaries/SoftErrorBoundary.razor @@ -7,13 +7,35 @@ @inject AlertService AlertService @inject SmartTranslateService SmartTranslateService -@ChildContent +@if (Crashed) +{ +
+
+
+
+ + Ooops. This page is crashed + +
+
+ This page is crashed. The error has been reported to the moonlight team. Meanwhile you can try reloading the page +
+
+
+
+} +else +{ + @ChildContent +} @code { + private bool Crashed = false; + protected override async Task OnErrorAsync(Exception exception) { - Logger.Debug(exception); + Logger.Warn(exception); if (exception is DisplayException displayException) { @@ -49,7 +71,8 @@ } else { - throw exception; + Crashed = true; + await InvokeAsync(StateHasChanged); } } } \ No newline at end of file diff --git a/Moonlight/Shared/Layouts/MainLayout.razor b/Moonlight/Shared/Layouts/MainLayout.razor index 4c42ecb..46017b5 100644 --- a/Moonlight/Shared/Layouts/MainLayout.razor +++ b/Moonlight/Shared/Layouts/MainLayout.razor @@ -59,57 +59,55 @@
- - - @if (uri.LocalPath != "/login" && - uri.LocalPath != "/passwordreset" && - uri.LocalPath != "/register") + + @if (uri.LocalPath != "/login" && + uri.LocalPath != "/passwordreset" && + uri.LocalPath != "/register") + { + if (User == null) { - if (User == null) - { - - } - else - { - if (User.Status == UserStatus.Banned) - { - - } - else if (User.Status == UserStatus.Disabled) - { - - } - else if (User.Status == UserStatus.PasswordPending) - { - - } - else if (User.Status == UserStatus.DataPending) - { - - } - else - { - @Body - } - } + } else { - if (uri.LocalPath == "/login") + if (User.Status == UserStatus.Banned) { - + } - else if (uri.LocalPath == "/register") + else if (User.Status == UserStatus.Disabled) { - + } - else if (uri.LocalPath == "/passwordreset") + else if (User.Status == UserStatus.PasswordPending) { - + + } + else if (User.Status == UserStatus.DataPending) + { + + } + else + { + @Body } } - - + } + else + { + if (uri.LocalPath == "/login") + { + + } + else if (uri.LocalPath == "/register") + { + + } + else if (uri.LocalPath == "/passwordreset") + { + + } + } +
@@ -161,8 +159,8 @@ await JsRuntime.InvokeVoidAsync("document.body.removeAttribute", "data-kt-app-page-loading"); await JsRuntime.InvokeVoidAsync("KTMenu.createInstances"); await JsRuntime.InvokeVoidAsync("KTDrawer.createInstances"); - - //await JsRuntime.InvokeVoidAsync("createSnow"); + + //await JsRuntime.InvokeVoidAsync("createSnow"); await SessionService.Register(); diff --git a/Moonlight/Shared/Views/Test.razor b/Moonlight/Shared/Views/Test.razor index 88c12f0..906f424 100644 --- a/Moonlight/Shared/Views/Test.razor +++ b/Moonlight/Shared/Views/Test.razor @@ -1,39 +1,12 @@ @page "/test" -@using Moonlight.App.Repositories -@using Moonlight.App.Database.Entities -@using Moonlight.App.Models.Forms - -@inject UserRepository UserRepository - -
- -
-
- -
-
@code { - private User[] Users; - private TestDataModel Model = new(); - private Task Load(LazyLoader arg) { - Users = UserRepository.Get().ToArray(); - - return Task.CompletedTask; - } - - private Task OnValidSubmit() - { - return Task.CompletedTask; + throw new Exception("Nein"); } }