Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APIPUB-86] - API Publisher some exceptions are hidden when using a remediation script #90

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,50 +178,51 @@ private async Task<IEnumerable<ErrorItemMessage>> HandlePostItemMessage(
delay,
async (result, ts, retryAttempt, ctx) =>
{
if (javaScriptModuleFactory != null)
{
var remediationResult = await TryRemediateFailureAsync(
javaScriptModuleFactory,
retryAttempt,
targetEdFiApiClient,
_sourceConnectionDetails.Name,
postItemMessage.ResourceUrl,
id,
result.Result,
postItemMessage.Item.ToString());

if (!remediationResult.FoundRemediation)
{
knownUnremediatedRequests.Add((postItemMessage.ResourceUrl, result.Result.StatusCode));

return;
}

// Check for a modified request body, and save it to the context
if (remediationResult.ModifiedRequestBody is JsonElement modifiedRequestBody
&& modifiedRequestBody.ValueKind != JsonValueKind.Null)
{
if (_logger.IsEnabled(LogEventLevel.Debug))
{
string modifiedRequestBodyJson = JsonSerializer.Serialize(
remediationResult.ModifiedRequestBody,
new JsonSerializerOptions { WriteIndented = true });

var message = $"{postItemMessage.ResourceUrl} (source id: {id}): Remediation plan provided a modified request body: {modifiedRequestBodyJson}";
_logger.Debug(message);
}

ctx["ModifiedRequestBody"] = remediationResult.ModifiedRequestBody;
}
}

if (result.Exception != null)
{
_logger.Warning(result.Exception, "{ResourceUrl} (source id: {Id}): POST attempt #{Attempts} failed with an exception. Retrying... (retry #{RetryAttempt} of {MaxRetryAttempts} with {TotalSeconds:N1}s delay):{NewLine}{Exception}",
postItemMessage.ResourceUrl, id, attempts, retryAttempt, options.MaxRetryAttempts, ts.TotalSeconds, Environment.NewLine, result.Exception);
}
else
{
if (javaScriptModuleFactory != null)
{
var remediationResult = await TryRemediateFailureAsync(
javaScriptModuleFactory,
retryAttempt,
targetEdFiApiClient,
_sourceConnectionDetails.Name,
postItemMessage.ResourceUrl,
id,
result.Result,
postItemMessage.Item.ToString());

if (!remediationResult.FoundRemediation)
{
knownUnremediatedRequests.Add((postItemMessage.ResourceUrl, result.Result.StatusCode));

return;
}

// Check for a modified request body, and save it to the context
if (remediationResult.ModifiedRequestBody is JsonElement modifiedRequestBody
&& modifiedRequestBody.ValueKind != JsonValueKind.Null)
{
if (_logger.IsEnabled(LogEventLevel.Debug))
{
string modifiedRequestBodyJson = JsonSerializer.Serialize(
remediationResult.ModifiedRequestBody,
new JsonSerializerOptions { WriteIndented = true });

_logger.Debug("{ResourceUrl} (source id: {Id}): Remediation plan provided a modified request body: {ModifiedRequestBodyJson}",
postItemMessage.ResourceUrl,
id,
modifiedRequestBodyJson);
}

ctx["ModifiedRequestBody"] = remediationResult.ModifiedRequestBody;
}
}
string responseContent = await result.Result.Content.ReadAsStringAsync().ConfigureAwait(false);

var message = $"{postItemMessage.ResourceUrl} (source id: {id}): POST attempt #{attempts} failed with status '{result.Result.StatusCode}'. Retrying... (retry #{retryAttempt} of {options.MaxRetryAttempts} with {ts.TotalSeconds:N1}s delay):{Environment.NewLine}{responseContent}";
Expand Down
Loading