Skip to content

Commit

Permalink
Modified data management controller logging to only log 500 status re…
Browse files Browse the repository at this point in the history
…sponses as errors.
  • Loading branch information
gmcelhanon committed Jan 6, 2025
1 parent eb38ae4 commit 12cc2ac
Showing 1 changed file with 16 additions and 11 deletions.
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

0 comments on commit 12cc2ac

Please sign in to comment.