31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|