Improve null-checking and error handling in Handle

Simplified null-checks in the `Handle` method of the
`BodyQueryBehavior` class using the null-conditional operator.
Enhanced the exception message to include `ProfileId` and
`ActionId` for better debugging context when `result?.RawBody`
is null.
This commit is contained in:
Developer 02 2025-11-28 23:37:09 +01:00
parent 97c57d4fb1
commit cc787f445a

View File

@ -9,14 +9,16 @@ 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);
var result = await dbContext.BodyQueryResults.FromSqlRaw(action.BodyQuery).FirstOrDefaultAsync(cancel);
if (result is null || result.RawBody is null)
throw new InvalidOperationException("Body query did not return a result or returned a null REQUEST_BODY.");
if (result?.RawBody is null)
throw new InvalidOperationException(
$"Body query did not return a result or returned a null REQUEST_BODY. " +
$"ProfileId: {action.ProfileId}, ActionId: {action.ActionId}.");
action.Body = result.RawBody;