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

[ODS-6581] Reduce severity level for API log entries for non-error response statuses from ERROR to DEBUG #1199

Merged
merged 1 commit into from
Jan 7, 2025
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 @@ -116,12 +116,22 @@ protected ILog Logger
}
}

private IActionResult CreateActionResultFromException(Exception exception)
private IActionResult CreateActionResultFromException(string actionName, Exception exception)
{
HttpContext.Items.TryAdd("Exception", exception);

// Process translations to Problem Details
var problemDetails = _problemDetailsProvider.GetProblemDetails(exception);

if (problemDetails.Status >= StatusCodes.Status500InternalServerError)
{
Logger.Error(actionName, exception);
}
else
{
Logger.Debug(actionName, exception);
}

return StatusCode(problemDetails.Status, problemDetails);
}

Expand Down Expand Up @@ -186,8 +196,7 @@ public virtual async Task<IActionResult> GetAll(
// Handle exception result
if (result.Exception != null)
{
Logger.Error(GetAllRequest, result.Exception);
return CreateActionResultFromException(result.Exception);
return CreateActionResultFromException(nameof(GetAll), result.Exception);
}

// Return multiple results
Expand Down Expand Up @@ -221,8 +230,7 @@ public virtual async Task<IActionResult> Get(Guid id)
// Handle exception result
if (result.Exception != null)
{
Logger.Error(GetByIdRequest, result.Exception);
return CreateActionResultFromException(result.Exception);
return CreateActionResultFromException(nameof(Get), result.Exception);
}

// Handle success result
Expand Down Expand Up @@ -296,8 +304,7 @@ public virtual async Task<IActionResult> Put([FromBody] TPutRequest request, Gui
// Check for exceptions
if (result.Exception != null)
{
Logger.Error("Put", result.Exception);
return CreateActionResultFromException(result.Exception);
return CreateActionResultFromException(nameof(Put), result.Exception);
}

// Check for validation errors
Expand Down Expand Up @@ -384,8 +391,7 @@ public virtual async Task<IActionResult> Post([FromBody] TPostRequest request)
// Throw an exceptions that occurred for global exception handling
if (result.Exception != null)
{
Logger.Error("Post", result.Exception);
return CreateActionResultFromException(result.Exception);
return CreateActionResultFromException(nameof(Post), result.Exception);
}

// Check for validation errors
Expand Down Expand Up @@ -442,8 +448,7 @@ public virtual async Task<IActionResult> Delete(Guid id)
// Throw an exceptions that occurred for global exception handling
if (result.Exception != null)
{
Logger.Error("Delete", result.Exception);
return CreateActionResultFromException(result.Exception);
return CreateActionResultFromException(nameof(Delete), result.Exception);
}

//Return 204 (according to RFC 2616, if the delete action has been enacted but the response does not include an entity, the return code should be 204).
Expand Down
Loading