mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
Add good error message when transcoder is not available
This commit is contained in:
parent
53285059c5
commit
19c5efaed0
@ -19,8 +19,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AspNetCore.Proxy;
|
using AspNetCore.Proxy;
|
||||||
|
using AspNetCore.Proxy.Options;
|
||||||
using Kyoo.Abstractions.Models.Permissions;
|
using Kyoo.Abstractions.Models.Permissions;
|
||||||
|
using Kyoo.Abstractions.Models.Utils;
|
||||||
using Kyoo.Utils;
|
using Kyoo.Utils;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Kyoo.Core.Api
|
namespace Kyoo.Core.Api
|
||||||
@ -31,6 +34,12 @@ namespace Kyoo.Core.Api
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class ProxyApi : Controller
|
public class ProxyApi : Controller
|
||||||
{
|
{
|
||||||
|
private readonly HttpProxyOptions _proxyOptions = HttpProxyOptionsBuilder.Instance.WithHandleFailure(async (context, exception) =>
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = StatusCodes.Status503ServiceUnavailable;
|
||||||
|
await context.Response.WriteAsJsonAsync(new RequestError("Service unavailable"));
|
||||||
|
}).Build();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Transcoder proxy
|
/// Transcoder proxy
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -44,7 +53,7 @@ namespace Kyoo.Core.Api
|
|||||||
public Task Proxy(string rest, [FromQuery] Dictionary<string, string> query)
|
public Task Proxy(string rest, [FromQuery] Dictionary<string, string> query)
|
||||||
{
|
{
|
||||||
// TODO: Use an env var to configure transcoder:7666.
|
// TODO: Use an env var to configure transcoder:7666.
|
||||||
return this.HttpProxyAsync($"http://transcoder:7666/{rest}" + query.ToQueryString());
|
return this.HttpProxyAsync($"http://transcoder:7666/{rest}" + query.ToQueryString(), _proxyOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user