aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Filters/RetryOnTemporarlyUnavailableFilter.cs
blob: bd572df9b7b64f94db50632d7af0c05b61ac8466 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Net.Http.Headers;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Jellyfin.Server.Filters;

internal class RetryOnTemporarlyUnavailableFilter : IOperationFilter
{
    public void Apply(OpenApiOperation operation, OperationFilterContext context)
    {
        operation.Responses.Add("503", new OpenApiResponse()
        {
            Description = "The server is currently starting or is temporarly not available.",
            Headers = new Dictionary<string, OpenApiHeader>()
            {
                {
                    "retry-after",
                    new() { AllowEmptyValue = true, Required = false, Description = "A hint for when to retry the operation." }
                },
                {
                    "message",
                    new() { AllowEmptyValue = true, Required = false, Description = "A short plain-text reason why the server is not available." }
                }
            },
            Content = new Dictionary<string, OpenApiMediaType>()
            {
                {
                    "text/html",
                    new OpenApiMediaType()
                }
            }
        });
    }
}