I have an async controller that returns results from a collection.
Sometimes, I will get an intermittent error if I click around the page to fast.
The errors are (in the browser console):
Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR
Or it will return this error from the front-end:
500 : Ajax request has failed
I have tried debugging locally in Visual Studio and stepping through the code, but locally, I don't get any errors and I can't figure out why it's doing it.
I have added a line that checks to make sure the returned collection is not null, so it's not that.
Here is the controller:
[HttpGet("factapi/Factory/{factoryId}/engines")]
public async Task<IActionResult> Get(Int32 factoryId)
{
using (var tran = Session.BeginTransaction())
{
var engineId = page.Assembly.Id.TrimToNull();
if (engineId == null) return NoContent();
var engines = await GetEngines(new Guid(engineId));
if (engines == null)
{
return BadRequest();
}
return Ok(engines);
}
}
This is the async method that gets the engines:
public async Task<IEnumerable<Engine>> GetEngines(Guid id)
{
var engines = new List<Engine>();
engines = await GetEngineList<Engine>(id);
return engines.Where(t => start.LiesBetween(t.BuildTime.AddMinutes( - 7), t.BuildTime.AddMinutes((t.TimeBreak / 60) + 7)));
}
And here is GetEngineList:
public async Task<List<T>> GetEngineList<T>(Guid id)
{
List<T> collectionVal = default(List<T>);
var factoryResponse = await GetList(id);
var fullList = factoryResponse.Results;
var settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
MissingMemberHandling = MissingMemberHandling.Ignore
};
var json = JsonConvert.SerializeObject(fullList);
var final = JsonConvert.DeserializeObject<List<T>>(json, settings);
collectionVal = final;
return collectionVal;
}
Another set of eyes would be welcome! :)