Add validation for BodyQuery result in Handle method
Previously, the `Handle` method in `BodyQueryBehavior<TRecAction>` did not validate the `BodyQuery` result before setting `action.Body`. This change introduces a check to ensure that the result and its `RawBody` are not null. If either is null, an `InvalidOperationException` is thrown with a clear error message. This ensures `action.Body` is only set when a valid result is retrieved, improving robustness and preventing potential null reference issues.
This commit is contained in:
parent
ff3908cdd2
commit
97c57d4fb1
@ -12,9 +12,13 @@ public class BodyQueryBehavior<TRecAction>(IRecDbContext dbContext) : IPipelineB
|
||||
{
|
||||
if (action.BodyQuery is null)
|
||||
return await next(cancel);
|
||||
|
||||
|
||||
var result = await dbContext.BodyQueryResults.FromSqlRaw(action.BodyQuery).FirstOrDefaultAsync(cancel);
|
||||
action.Body = result?.RawBody;
|
||||
|
||||
if (result is null || result.RawBody is null)
|
||||
throw new InvalidOperationException("Body query did not return a result or returned a null REQUEST_BODY.");
|
||||
|
||||
action.Body = result.RawBody;
|
||||
|
||||
return await next(cancel);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user