Improve HeaderQueryBehavior error handling and logging
Updated HeaderQueryBehavior to handle null or missing REQUEST_HEADER gracefully by logging warnings and setting action.IsReturnedNoData.HeaderQuery to true instead of throwing exceptions. Enhanced log messages for failed RawHeader deserialization to improve clarity and added pipeline continuity by calling await next(cancel). Refactored log formatting for consistency.
This commit is contained in:
parent
0d801466cf
commit
e0736ff6df
@ -18,15 +18,24 @@ public class HeaderQueryBehavior<TRecAction>(IRecDbContext dbContext, ILogger<He
|
||||
var result = await dbContext.HeaderQueryResults.FromSqlRaw(action.HeaderQuery).FirstOrDefaultAsync(cancel);
|
||||
|
||||
if(result?.RawHeader is null)
|
||||
throw new InvalidOperationException(
|
||||
$"Header query did not return a result or returned a null REQUEST_HEADER. " +
|
||||
$"ProfileId: {action.ProfileId}, ActionId: {action.ActionId}.");
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user