Skip to content

Commit

Permalink
Catch OperationCanceledException explicitly (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
karashiiro authored Jul 18, 2024
1 parent 0c36de5 commit 70627ea
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using UAParser;
using Universalis.Application.Common;
using Universalis.Application.Swagger;
Expand Down Expand Up @@ -98,14 +99,6 @@ public async Task<IActionResult> Get(
return NotFound();
}

if (worldDc.IsRegion)
{
return BadRequest(new
{
Message = "Region-wide calls are temporarily disabled due to load.",
});
}

if (!TryGetWorldIds(worldDc, out var worldIds))
{
return NotFound();
Expand Down Expand Up @@ -167,23 +160,30 @@ public async Task<IActionResult> Get(
itemsSerializableProperties,
cts.Token))
.ToList();
var currentlyShownViews = await Task.WhenAll(currentlyShownViewTasks);
var unresolvedItems = currentlyShownViews
.Where(cs => !cs.Item1)
.Select(cs => cs.Item2.ItemId)
.ToArray();
return Ok(new CurrentlyShownMultiView
try
{
ItemIds = itemIdsArray.ToList(),
Items = currentlyShownViews
.Where(cs => cs.Item1)
.Select(cs => cs.Item2)
.ToList(),
WorldId = worldDc.IsWorld ? worldDc.WorldId : null,
WorldName = worldDc.IsWorld ? worldDc.WorldName : null,
DcName = worldDc.IsDc ? worldDc.DcName : null,
UnresolvedItemIds = unresolvedItems,
SerializableProperties = serializableProperties,
});
var currentlyShownViews = await Task.WhenAll(currentlyShownViewTasks);
var unresolvedItems = currentlyShownViews
.Where(cs => !cs.Item1)
.Select(cs => cs.Item2.ItemId)
.ToArray();
return Ok(new CurrentlyShownMultiView
{
ItemIds = itemIdsArray.ToList(),
Items = currentlyShownViews
.Where(cs => cs.Item1)
.Select(cs => cs.Item2)
.ToList(),
WorldId = worldDc.IsWorld ? worldDc.WorldId : null,
WorldName = worldDc.IsWorld ? worldDc.WorldName : null,
DcName = worldDc.IsDc ? worldDc.DcName : null,
UnresolvedItemIds = unresolvedItems,
SerializableProperties = serializableProperties,
});
}
catch (OperationCanceledException)
{
return StatusCode(StatusCodes.Status504GatewayTimeout);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using UAParser;
using Universalis.Application.Common;
using Universalis.Application.Swagger;
Expand Down Expand Up @@ -97,14 +98,6 @@ public async Task<IActionResult> Get(
return NotFound();
}

if (worldDc.IsRegion)
{
return BadRequest(new
{
Message = "Region-wide calls are temporarily disabled due to load.",
});
}

if (!TryGetWorldIds(worldDc, out var worldIds))
{
return NotFound();
Expand Down Expand Up @@ -165,24 +158,31 @@ public async Task<IActionResult> Get(
itemsSerializableProperties,
cts.Token))
.ToList();
var currentlyShownViews = await Task.WhenAll(currentlyShownViewTasks);
var unresolvedItems = currentlyShownViews
.Where(cs => !cs.Item1)
.Select(cs => cs.Item2.ItemId)
.ToArray();
return Ok(new CurrentlyShownMultiViewV2
try
{
ItemIds = itemIdsArray.ToList(),
Items = currentlyShownViews
.Where(cs => cs.Item1)
.Select(cs => cs.Item2)
.ToDictionary(item => item.ItemId, item => item),
WorldId = worldDc.IsWorld ? worldDc.WorldId : null,
WorldName = worldDc.IsWorld ? worldDc.WorldName : null,
DcName = worldDc.IsDc ? worldDc.DcName : null,
RegionName = worldDc.IsRegion ? worldDc.RegionName : null,
UnresolvedItemIds = unresolvedItems,
SerializableProperties = serializableProperties,
});
var currentlyShownViews = await Task.WhenAll(currentlyShownViewTasks);
var unresolvedItems = currentlyShownViews
.Where(cs => !cs.Item1)
.Select(cs => cs.Item2.ItemId)
.ToArray();
return Ok(new CurrentlyShownMultiViewV2
{
ItemIds = itemIdsArray.ToList(),
Items = currentlyShownViews
.Where(cs => cs.Item1)
.Select(cs => cs.Item2)
.ToDictionary(item => item.ItemId, item => item),
WorldId = worldDc.IsWorld ? worldDc.WorldId : null,
WorldName = worldDc.IsWorld ? worldDc.WorldName : null,
DcName = worldDc.IsDc ? worldDc.DcName : null,
RegionName = worldDc.IsRegion ? worldDc.RegionName : null,
UnresolvedItemIds = unresolvedItems,
SerializableProperties = serializableProperties,
});
}
catch (OperationCanceledException)
{
return StatusCode(StatusCodes.Status504GatewayTimeout);
}
}
}

0 comments on commit 70627ea

Please sign in to comment.