Catch exceptions while loading remote files

This commit is contained in:
ds5678 2025-03-30 23:07:33 -07:00
parent 07563989e1
commit 48bd179426

View File

@ -53,15 +53,22 @@ internal static class RoutingExtensions
{
return endpoints.MapGet(path, async (context) =>
{
string fileName = Path.GetFileName(path);
byte[] data = await StaticContentLoader.LoadRemote(path, source, integrity);
if (data.Length == 0)
try
{
await Results.NotFound().ExecuteAsync(context);
string fileName = Path.GetFileName(path);
byte[] data = await StaticContentLoader.LoadRemote(path, source, integrity);
if (data.Length == 0)
{
await Results.NotFound().ExecuteAsync(context);
}
else
{
await Results.Bytes(data, contentType, fileName).ExecuteAsync(context);
}
}
else
catch (Exception ex)
{
await Results.Bytes(data, contentType, fileName).ExecuteAsync(context);
await Results.InternalServerError(ex.ToString()).ExecuteAsync(context);
}
}).Produces<byte[]>(StatusCodes.Status200OK, contentType);
}