From cc787f445acd3f72d41db1c8683932d6a0acca70 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 28 Nov 2025 23:37:09 +0100 Subject: [PATCH] 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. --- src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs b/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs index 3c533fc..fa77ffb 100644 --- a/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs +++ b/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs @@ -9,14 +9,16 @@ public class BodyQueryBehavior(IRecDbContext dbContext) : IPipelineB where TRecAction : RecActionDto { public async Task Handle(TRecAction action, RequestHandlerDelegate 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;