Serve 503 when PocketBase is unavailable across all content pages
This commit is contained in:
1 parent
0f7e968c16
commit
e242eaf79a
25 files changed
+492
-253
No files matched your search
@@ -6,14 +6,19 @@ namespace Elternbeirat.Web.Components.Layout;
|
||||
|
||||
public partial class MainLayout
|
||||
{
|
||||
[LoggerMessage(Level = LogLevel.Warning, Message = "Could not load navigation pages from PocketBase.")]
|
||||
private static partial void LogLoadFailed(ILogger logger, Exception exception);
|
||||
[LoggerMessage(
|
||||
Level = LogLevel.Warning,
|
||||
Message = "Could not load navigation pages from PocketBase; the menu is empty.")]
|
||||
private static partial void LogSourceUnavailable(ILogger logger, Exception exception);
|
||||
|
||||
[Inject]
|
||||
private PocketBaseClient PocketBase { get; set; } = default!;
|
||||
private PocketBaseClient PocketBase { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
private ILogger<MainLayout> Logger { get; set; } = default!;
|
||||
private ILogger<MainLayout> Logger { get; set; } = null!;
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext? HttpContext { get; set; }
|
||||
|
||||
private IReadOnlyList<NavLinkItem> _header = [];
|
||||
private IReadOnlyList<NavLinkItem> _footer = [];
|
||||
@@ -22,15 +27,15 @@ public partial class MainLayout
|
||||
{
|
||||
try
|
||||
{
|
||||
var pages = await PocketBase.GetPagesAsync();
|
||||
var pages = await PocketBase.GetPagesAsync(HttpContext?.RequestAborted ?? default);
|
||||
_header = NavBuilder.Header(pages);
|
||||
_footer = NavBuilder.Footer(pages);
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
catch (PocketBaseUnavailableException ex)
|
||||
{
|
||||
// Source unreachable -> render the chrome with an empty menu instead of
|
||||
// a 500. The brand link still leads home.
|
||||
LogLoadFailed(Logger, ex);
|
||||
// Only the menu fails: render the chrome with an empty menu instead of a
|
||||
// 500, so every page stays reachable. The brand link still leads home.
|
||||
LogSourceUnavailable(Logger, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user