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
@@ -8,8 +8,8 @@ public partial class Home
|
||||
{
|
||||
[LoggerMessage(
|
||||
Level = LogLevel.Warning,
|
||||
Message = "Could not load the home page from PocketBase.")]
|
||||
private static partial void LogLoadFailed(
|
||||
Message = "Could not load the home page from PocketBase; embeds are omitted.")]
|
||||
private static partial void LogSourceUnavailable(
|
||||
ILogger logger,
|
||||
Exception exception);
|
||||
|
||||
@@ -19,6 +19,9 @@ public partial class Home
|
||||
[Inject]
|
||||
private ILogger<Home> Logger { get; set; } = null!;
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext? HttpContext { get; set; }
|
||||
|
||||
// Which dynamic blocks the home page shows is editorial: it comes from the
|
||||
// "home" page's embed field in PocketBase, not from hard-coded markup.
|
||||
private IReadOnlyList<string> _embed = [];
|
||||
@@ -27,14 +30,15 @@ public partial class Home
|
||||
{
|
||||
try
|
||||
{
|
||||
var pages = await PocketBase.GetPagesAsync();
|
||||
var pages = await PocketBase.GetPagesAsync(HttpContext?.RequestAborted ?? default);
|
||||
var home = pages.FirstOrDefault(page => Page.IsHomeSlug(page.Slug));
|
||||
_embed = home?.Embed ?? [];
|
||||
}
|
||||
catch (HttpRequestException exception)
|
||||
catch (PocketBaseUnavailableException exception)
|
||||
{
|
||||
// Source unreachable -> render the intro without embeds instead of a 500.
|
||||
LogLoadFailed(Logger, exception);
|
||||
// Only the embeds fail: render the static intro without them instead of a
|
||||
// 500. The home page's own text is markup, so it stays intact.
|
||||
LogSourceUnavailable(Logger, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user