From 871816f19266e77012d0731c66a5983da3d89f20 Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Sat, 31 Dec 2022 17:19:50 +0100 Subject: [PATCH] Adding error handler --- src/CraftSharp/App.razor | 4 +++- src/CraftSharp/App.razor.cs | 26 ++++++++++++++++++++++ src/CraftSharp/Shared/ErrorLayout.razor.cs | 20 ----------------- src/CraftSharp/Shared/SurveyPrompt.razor | 16 ------------- 4 files changed, 29 insertions(+), 37 deletions(-) create mode 100644 src/CraftSharp/App.razor.cs delete mode 100644 src/CraftSharp/Shared/ErrorLayout.razor.cs delete mode 100644 src/CraftSharp/Shared/SurveyPrompt.razor diff --git a/src/CraftSharp/App.razor b/src/CraftSharp/App.razor index 44f1858..ca31ce6 100644 --- a/src/CraftSharp/App.razor +++ b/src/CraftSharp/App.razor @@ -8,10 +8,12 @@ - + + @{ErrorHandler(5);}


Oups, la page que à laquelle vous essayez d'accéder n'existe pas ! +

Retour à la page d'accueil dans 5s



diff --git a/src/CraftSharp/App.razor.cs b/src/CraftSharp/App.razor.cs new file mode 100644 index 0000000..915b810 --- /dev/null +++ b/src/CraftSharp/App.razor.cs @@ -0,0 +1,26 @@ +using CraftSharp.Shared; +using Microsoft.AspNetCore.Components; + +namespace CraftSharp +{ + public partial class App + { + [Inject] + public NavigationManager NavigationManager { get; set; } + + [Inject] + public ILogger Logger { get; set; } + + public async Task ErrorHandler(int countdown) { + Logger.Log(LogLevel.Error, $"Navigating to unknown page : {NavigationManager.Uri}"); + while(countdown > 0) + { + await Task.Delay(1000); + countdown--; + StateHasChanged(); + } + NavigationManager.NavigateTo("index"); + } + + } +} diff --git a/src/CraftSharp/Shared/ErrorLayout.razor.cs b/src/CraftSharp/Shared/ErrorLayout.razor.cs deleted file mode 100644 index 0d30d0e..0000000 --- a/src/CraftSharp/Shared/ErrorLayout.razor.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.AspNetCore.Components; -using Microsoft.Extensions.Localization; -using System.Net.Http; - -namespace CraftSharp.Shared -{ - public partial class ErrorLayout - { - [Inject] - public ILogger Logger { get; set; } - - [Inject] - public NavigationManager NavigationManager { get; set; } - - protected override async Task OnInitializedAsync() - { - Logger.Log(LogLevel.Error, $"Navigating to unknown page : {NavigationManager.Uri}"); - } - } -} diff --git a/src/CraftSharp/Shared/SurveyPrompt.razor b/src/CraftSharp/Shared/SurveyPrompt.razor deleted file mode 100644 index e3e6429..0000000 --- a/src/CraftSharp/Shared/SurveyPrompt.razor +++ /dev/null @@ -1,16 +0,0 @@ -
- - @Title - - - Please take our - brief survey - - and tell us what you think. -
- -@code { - // Demonstrates how a parent component can supply parameters - [Parameter] - public string? Title { get; set; } -}