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
@@ -0,0 +1,30 @@
|
||||
namespace Elternbeirat.Web.Shared;
|
||||
|
||||
/// <summary>
|
||||
/// Marks the current response as HTTP 503 when the content source is down.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Several components handle a <see cref="PocketBase.PocketBaseUnavailableException"/>
|
||||
/// the same way: the site works but PocketBase does not, so the response is a
|
||||
/// 503 and the component renders a "temporarily unavailable" note instead of
|
||||
/// empty content that would read as 200 "there is nothing here". This puts the
|
||||
/// status-setting in one place so those components do not each repeat it.
|
||||
/// </remarks>
|
||||
internal static class SourceUnavailable
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the response status to 503 Service Unavailable, if there is a
|
||||
/// response to set it on.
|
||||
/// </summary>
|
||||
/// <param name="context">
|
||||
/// The current HTTP context, or <see langword="null"/> when the component
|
||||
/// renders outside a request (in which case there is nothing to do).
|
||||
/// </param>
|
||||
public static void SetStatus(HttpContext? context)
|
||||
{
|
||||
if (context is not null)
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status503ServiceUnavailable;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user