Compare commits

...

8 Commits

Author SHA1 Message Date
Developer 02
b78b3e43f4 Add support for custom headers in HTTP requests
Enhanced HTTP request handling by adding support for dynamically including custom headers from the `request.Headers` collection. Implemented a null check to ensure robustness and prevent null reference exceptions when processing headers. This change improves flexibility and customization of HTTP requests.
2025-12-01 09:45:41 +01:00
Developer 02
07afcf3aa2 Add logging for unexpected BodyQuery and IsReturnedNoData
Improve observability by adding a warning log when `request.BodyQuery` is not null but `request.IsReturnedNoData.BodyQuery` is false.

The log message highlights potential issues, such as skipped `BodyQueryBehavior` execution or missing control steps, and includes `ProfileId` and `ActionId` for better debugging context.
2025-11-29 01:12:03 +01:00
Developer 02
e0736ff6df 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.
2025-11-29 00:55:43 +01:00
Developer 02
0d801466cf Add properties for query tracking and post-processing
Added `IsReturnedNoData` property as a tuple to track the state
of `BodyQuery` and `HeaderQuery` data returns. Introduced
`PostprocessingQuery` property to support initialization of
post-processing queries. These changes enhance the functionality
of the `RecActionDto` class by enabling better query handling
and processing capabilities.
2025-11-29 00:36:03 +01:00
Developer 02
ff53be5d13 Throw exception for null RawHeader in HeaderQueryBehavior
Previously, the code continued execution when the RawHeader
property of the query result was null. This change introduces
an InvalidOperationException to handle this case, ensuring
that the absence of a valid RawHeader is treated as an error.
The exception message includes ProfileId and ActionId for
better debugging context.
2025-11-28 23:41:35 +01:00
Developer 02
cc787f445a 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.
2025-11-28 23:37:09 +01:00
Developer 02
97c57d4fb1 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.
2025-11-28 23:32:28 +01:00
Developer 02
ff3908cdd2 Support HTTP request body in InvokeRecActionCommandHandler
Added logic to handle non-null `request.Body` in HTTP requests.
Introduced a `StringContent` object to encapsulate the body
content and assigned it to the `Content` property of the
HTTP request. This ensures that the request body is included
when sending data to the specified endpoint.
2025-11-28 23:24:36 +01:00
4 changed files with 44 additions and 4 deletions

View File

@ -9,12 +9,18 @@ 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);
action.Body = result?.RawBody;
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;
return await next(cancel);
}

View File

@ -18,13 +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)
{
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);
}

View File

@ -60,6 +60,8 @@ public record RecActionDto
public string? Body { get; set; }
public (bool BodyQuery, bool HeaderQuery) IsReturnedNoData = (false, false);
public string? PostprocessingQuery { get; init; }
public UriBuilder ToEndpointUriBuilder()

View File

@ -40,6 +40,27 @@ public class InvokeRecActionCommandHandler(
.ToHttpMethod()
.ToHttpRequestMessage(request.EndpointUri);
if(request.Body is not null)
{
using var reqBody = new StringContent(request.Body);
httpReq.Content = reqBody;
}
else if(request.BodyQuery is not null && !request.IsReturnedNoData.BodyQuery)
{
logger?.LogWarning(
"Although BodyQuery returns null, the IsReturnedNoData variable has not been set to TRUE. " +
"This indicates that BodyQueryBehavior has not been executed or that the relevant control step has been skipped. " +
"The relevant behavior must be verified to ensure that the process does not produce unexpected conditions. " +
"ProfileId: {ProfileId}, ActionId: {ActionId}",
request.ProfileId,
request.ActionId
);
}
if (request.Headers is not null)
foreach (var header in request.Headers)
httpReq.Headers.Add(header.Key, header.Value);
using var response = await http.SendAsync(httpReq, cancel);
var body = await response.Content.ReadAsStringAsync(cancel);
var headers = response.Headers.ToDictionary();