From 149db6db91af804af45080edd58719bb1db5199d Mon Sep 17 00:00:00 2001 From: Simon <63975668+Simyon264@users.noreply.github.com> Date: Fri, 23 Aug 2024 23:43:16 +0200 Subject: [PATCH] Add error pages --- ReplayBrowser/Pages/Shared/Layout/Error.razor | 5 ++ .../Pages/Shared/Layout/ErrorCode.razor | 75 +++++++++++++++++++ .../Pages/Shared/Layout/Routes.razor | 2 +- ReplayBrowser/Pages/ViewReplay.razor | 8 +- ReplayBrowser/Startup.cs | 1 + 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 ReplayBrowser/Pages/Shared/Layout/ErrorCode.razor diff --git a/ReplayBrowser/Pages/Shared/Layout/Error.razor b/ReplayBrowser/Pages/Shared/Layout/Error.razor index 59631b4..f25f1b5 100644 --- a/ReplayBrowser/Pages/Shared/Layout/Error.razor +++ b/ReplayBrowser/Pages/Shared/Layout/Error.razor @@ -4,6 +4,11 @@ Error + +

Error.

An error occurred while processing your request.

diff --git a/ReplayBrowser/Pages/Shared/Layout/ErrorCode.razor b/ReplayBrowser/Pages/Shared/Layout/ErrorCode.razor new file mode 100644 index 0000000..dbc9069 --- /dev/null +++ b/ReplayBrowser/Pages/Shared/Layout/ErrorCode.razor @@ -0,0 +1,75 @@ +@page "/error/{code:int}" + +@inject NavigationManager NavigationManager + +
+ @{ + switch (Code) + { + case 404: + +

404 Not Found

+

Oops. The page at doesn't exist. What a shame.

+ Should there be a page here? Contribute to the project on GitHub! + break; + case 500: + +

500 Internal Server Error

+

There was an error on the server. Please try again later.

+ How did you get here? The other error page *should* have caught this. + break; + default: + +

@Code

+

There was an error. Please try again later.

+ That's all we know. + break; + } + } +
+ + + + + + +@code { + [Parameter] + public int Code { get; set; } +} \ No newline at end of file diff --git a/ReplayBrowser/Pages/Shared/Layout/Routes.razor b/ReplayBrowser/Pages/Shared/Layout/Routes.razor index 5c59d6a..4f4e34c 100644 --- a/ReplayBrowser/Pages/Shared/Layout/Routes.razor +++ b/ReplayBrowser/Pages/Shared/Layout/Routes.razor @@ -1,4 +1,4 @@ - + diff --git a/ReplayBrowser/Pages/ViewReplay.razor b/ReplayBrowser/Pages/ViewReplay.razor index c2c3d1f..0f3fa23 100644 --- a/ReplayBrowser/Pages/ViewReplay.razor +++ b/ReplayBrowser/Pages/ViewReplay.razor @@ -9,11 +9,12 @@ @inject AuthenticationStateProvider AuthenticationStateProvider @inject ReplayHelper ReplayHelper @inject ReplayParserService ReplayParserService +@inject NavigationManager NavigationManager Replay viewer @if (Replay == null) { -

Replay not found

+

Loading...

} else { @@ -70,5 +71,10 @@ else { var authstate = await AuthenticationStateProvider.GetAuthenticationStateAsync(); Replay = await ReplayHelper.GetReplay(Id, authstate)!; + if (Replay == null) + { + var currentUrl = Uri.EscapeDataString(NavigationManager.Uri); + NavigationManager.NavigateTo($"/error/404?url={currentUrl}"); + } } } \ No newline at end of file diff --git a/ReplayBrowser/Startup.cs b/ReplayBrowser/Startup.cs index 8bdb137..dfd4f57 100644 --- a/ReplayBrowser/Startup.cs +++ b/ReplayBrowser/Startup.cs @@ -239,6 +239,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) #else app.UseDeveloperExceptionPage(); #endif + app.UseStatusCodePagesWithReExecute("/error/{0}"); app.UseHttpsRedirection();