Location error handling
Deploy Promiscuity Auth API / deploy (push) Successful in 45s
Deploy Promiscuity Character API / deploy (push) Successful in 45s
Deploy Promiscuity Inventory API / deploy (push) Successful in 45s
Deploy Promiscuity Locations API / deploy (push) Successful in 1m0s
k8s smoke test / test (push) Successful in 8s

This commit is contained in:
2026-03-19 16:54:06 -05:00
parent 82e4ae8a81
commit 52a76625a3
2 changed files with 83 additions and 16 deletions
@@ -17,12 +17,14 @@ public class LocationsController : ControllerBase
private readonly LocationStore _locations;
private readonly IHttpClientFactory _httpClientFactory;
private readonly IConfiguration _configuration;
private readonly ILogger<LocationsController> _logger;
public LocationsController(LocationStore locations, IHttpClientFactory httpClientFactory, IConfiguration configuration)
public LocationsController(LocationStore locations, IHttpClientFactory httpClientFactory, IConfiguration configuration, ILogger<LocationsController> logger)
{
_locations = locations;
_httpClientFactory = httpClientFactory;
_configuration = configuration;
_logger = logger;
}
[HttpPost]
@@ -140,26 +142,56 @@ public class LocationsController : ControllerBase
if (!string.IsNullOrWhiteSpace(token))
request.Headers.Authorization = AuthenticationHeaderValue.Parse(token);
using var response = await client.SendAsync(request);
var responseBody = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
HttpResponseMessage response;
try
{
response = await client.SendAsync(request);
}
catch (HttpRequestException ex)
{
if (interact.PreviousObject is not null)
await _locations.RestoreObjectInteractionAsync(id, interact.PreviousObject);
return StatusCode((int)response.StatusCode, responseBody);
_logger.LogError(
ex,
"Failed to reach InventoryApi while processing location interaction for location {LocationId}, character {CharacterId}, object {ObjectId}",
id,
req.CharacterId,
req.ObjectId
);
return StatusCode(StatusCodes.Status502BadGateway, new
{
type = "https://httpstatuses.com/502",
title = "Bad Gateway",
status = 502,
detail = $"Failed to reach InventoryApi at {inventoryBaseUrl}.",
traceId = HttpContext.TraceIdentifier
});
}
return Ok(new InteractLocationObjectResponse
using (response)
{
LocationId = id,
CharacterId = req.CharacterId,
ObjectId = interact.ObjectId,
ObjectType = interact.ObjectType,
ItemKey = interact.ItemKey,
QuantityGranted = interact.QuantityGranted,
RemainingQuantity = interact.RemainingQuantity,
Consumed = interact.Consumed,
InventoryResponseJson = responseBody
});
var responseBody = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
if (interact.PreviousObject is not null)
await _locations.RestoreObjectInteractionAsync(id, interact.PreviousObject);
return StatusCode((int)response.StatusCode, responseBody);
}
return Ok(new InteractLocationObjectResponse
{
LocationId = id,
CharacterId = req.CharacterId,
ObjectId = interact.ObjectId,
ObjectType = interact.ObjectType,
ItemKey = interact.ItemKey,
QuantityGranted = interact.QuantityGranted,
RemainingQuantity = interact.RemainingQuantity,
Consumed = interact.Consumed,
InventoryResponseJson = responseBody
});
}
}
}