Enhance query handling and diagnostics
Improved robustness and error handling in `BodyQueryBehavior` and `HeaderQueryBehavior` by adding null checks, logging, and introducing the `IsReturnedNoData` flag to track query results. Updated `RecActionDto` to include the new flag for better state management. Enhanced HTTP request construction in `InvokeRecActionCommand` to handle `Body` and `Headers` more reliably and log potential issues with unexecuted behaviors. These changes improve resilience, traceability, and diagnostics across the application.
This commit is contained in:
@@ -9,7 +9,7 @@ public class BodyQueryBehavior<TRecAction>(IRecDbContext dbContext) : IPipelineB
|
||||
where TRecAction : RecActionDto
|
||||
{
|
||||
public async Task<Unit> Handle(TRecAction action, RequestHandlerDelegate<Unit> next, CancellationToken cancel)
|
||||
{
|
||||
{
|
||||
if (action.BodyQuery is null)
|
||||
return await next(cancel);
|
||||
|
||||
|
||||
@@ -18,13 +18,24 @@ public class HeaderQueryBehavior<TRecAction>(IRecDbContext dbContext, ILogger<He
|
||||
var result = await dbContext.HeaderQueryResults.FromSqlRaw(action.HeaderQuery).SingleOrDefaultAsync(cancel);
|
||||
|
||||
if(result?.RawHeader is null)
|
||||
{
|
||||
logger?.LogWarning("Header query did not return a result or returned a null REQUEST_HEADER. Profile ID: {ProfileId}, Action ID: {ActionId}", action.ProfileId, action.ActionId);
|
||||
|
||||
action.IsReturnedNoData.HeaderQuery = true;
|
||||
|
||||
return await next(cancel);
|
||||
}
|
||||
|
||||
var headerDict = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(result.RawHeader);
|
||||
|
||||
if(headerDict is null)
|
||||
{
|
||||
logger?.LogWarning("Failed to deserialize header query result: {RawHeader}. Profile ID: {ProfileId}, Action ID: {ActionId}", result.RawHeader, action.ProfileId, action.ActionId);
|
||||
logger?.LogWarning(
|
||||
"Header JSON deserialization returned null. RawHeader: {RawHeader}, ProfileId: {ProfileId}, ActionId: {ActionId}",
|
||||
result.RawHeader, action.ProfileId, action.ActionId);
|
||||
|
||||
action.IsReturnedNoData.HeaderQuery = true;
|
||||
|
||||
return await next(cancel);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user