From 97c57d4fb13dcf112ddaf2badff20ca79968c914 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 28 Nov 2025 23:32:28 +0100 Subject: [PATCH] Add validation for BodyQuery result in Handle method Previously, the `Handle` method in `BodyQueryBehavior` 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. --- src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs b/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs index 77ed91c..3c533fc 100644 --- a/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs +++ b/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs @@ -12,9 +12,13 @@ public class BodyQueryBehavior(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); }