soat-fiap / FIAP.TechChallenge.ByteMeBurger

Repository for FIAP SOAT post degree Tech Challenge
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Implement error handling and logging in DeleteAsync method #34

Open coderabbitai[bot] opened 1 month ago

coderabbitai[bot] commented 1 month ago

In the method of the class, there is currently no error handling or logging implemented. This can lead to situations where errors during the database operation are silently ignored, making debugging difficult. It is crucial to wrap the database operation in a try-catch block and log the error before rethrowing or handling it appropriately.

Suggested Enhancement

public async Task<bool> DeleteAsync(Guid productId)
{
    try
    {
        var affectedRows = await _dbConnection.ExecuteAsync("delete from Products where Id = @Id;", new { Id = productId });
        return affectedRows == 1;
    }
    catch (Exception ex)
    {
        // Log the exception details here
        throw; // Rethrow the exception or handle it as needed
    }
}

Context

This issue is linked to PR #33 and the discussion can be found here.

@italopessoa, please review the details and adjust as necessary.