Skip to content

Commit

Permalink
Log unsuccessful opensearch responses (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
simpat-adam authored Dec 17, 2024
1 parent d09533e commit b3f1e95
Showing 1 changed file with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,13 @@ ILogger logger
}
}

JsonObject query =
new()
{
["query"] = new JsonObject { ["bool"] = new JsonObject { ["must"] = terms } },
["sort"] = SortDirective(),
};
JsonObject query = new()
{
["query"] = new JsonObject { ["bool"] = new JsonObject { ["must"] = terms } },
["sort"] = SortDirective(),
};

// Add in PaginationParameters if any

if (queryRequest.PaginationParameters.Limit != null)
{
query.Add(new("size", queryRequest.PaginationParameters.Limit));
Expand All @@ -142,22 +140,32 @@ ILogger logger
d => d.Body(query.ToJsonString())
);

JsonNode hits = JsonSerializer.Deserialize<JsonNode>(response.Body)!["hits"]!;

if (hits is null)
if (response.Success)
{
return new QueryResult.QuerySuccess(new JsonArray(), 0);
}
JsonNode hits = JsonSerializer.Deserialize<JsonNode>(response.Body)!["hits"]!;

if (hits is null)
{
return new QueryResult.QuerySuccess(new JsonArray(), 0);
}

int totalCount = hits!["total"]!["value"]!.GetValue<int>();

int totalCount = hits!["total"]!["value"]!.GetValue<int>();
JsonNode[] documents = hits!["hits"]!
.AsArray()
// DeepClone() so they can be placed in a new JsonArray
.Select(node => node!["_source"]!["edfidoc"]!.DeepClone())!
.ToArray()!;

JsonNode[] documents = hits!["hits"]!
.AsArray()
// DeepClone() so they can be placed in a new JsonArray
.Select(node => node!["_source"]!["edfidoc"]!.DeepClone())!
.ToArray()!;
return new QueryResult.QuerySuccess(new JsonArray(documents), totalCount);
}

return new QueryResult.QuerySuccess(new JsonArray(documents), totalCount);
logger.LogCritical(
"Unsuccessful OpenSearch Response - {TraceId} - {DebugInformation}",
queryRequest.TraceId.Value,
response.DebugInformation
);
return new QueryResult.UnknownFailure("Unknown Failure");
}
catch (Exception ex)
{
Expand Down

0 comments on commit b3f1e95

Please sign in to comment.