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,24 @@ namespace Elternbeirat.Web.Features.Embeds;
|
||||
|
||||
public partial class FaqsEmbed
|
||||
{
|
||||
[LoggerMessage(Level = LogLevel.Warning, Message = "Could not load FAQs for an embed from PocketBase.")]
|
||||
private static partial void LogLoadFailed(ILogger logger, Exception exception);
|
||||
// Number of questions shown in the teaser; the full hub is one link away.
|
||||
private const int TeaserCount = 3;
|
||||
|
||||
[LoggerMessage(
|
||||
Level = LogLevel.Warning,
|
||||
Message = "Could not load FAQs for an embed from PocketBase; the teaser is omitted.")]
|
||||
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<FaqsEmbed> Logger { get; set; } = default!;
|
||||
private ILogger<FaqsEmbed> Logger { get; set; } = null!;
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext? HttpContext { get; set; }
|
||||
|
||||
private IReadOnlyList<Faq> _faqs = [];
|
||||
|
||||
@@ -21,14 +31,16 @@ public partial class FaqsEmbed
|
||||
{
|
||||
try
|
||||
{
|
||||
// Teaser: the first three questions, with a link to the full hub.
|
||||
var faqs = await PocketBase.GetFaqsAsync();
|
||||
_faqs = [.. faqs.Take(3)];
|
||||
// GetFaqsAsync is ordered by topic, then question, so the first entries
|
||||
// the teaser takes are stable across requests.
|
||||
var faqs = await PocketBase.GetFaqsAsync(HttpContext?.RequestAborted ?? CancellationToken.None);
|
||||
_faqs = [.. faqs.Take(TeaserCount)];
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
catch (PocketBaseUnavailableException exception)
|
||||
{
|
||||
// Source unreachable -> show no teaser instead of a 500.
|
||||
LogLoadFailed(Logger, ex);
|
||||
// Only part of the page fails: omit the teaser, keep the page (and its
|
||||
// 200) intact. A missing teaser is degraded, not broken.
|
||||
LogSourceUnavailable(Logger, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user