C
C#16mo ago
dela

❔ I don't know where to put handle error in my project

I use DDD in my project and this project makes CRUD. In infrastructure, there are a logic to call a database and I thiking it's a good idea to put a handle error. For example:
public Task<Employee> GetEmployeeById (int id) {
var employee = await _employee.Find(x => x.Id == id).FirstOrDefaultAsync();

if(employee == null){
return NotFound();
}
}
public Task<Employee> GetEmployeeById (int id) {
var employee = await _employee.Find(x => x.Id == id).FirstOrDefaultAsync();

if(employee == null){
return NotFound();
}
}
But I think is a bad practice do that. It's a good practice do that but in a controller?. For example:
[HttpGet("{id}")]
public Task<IActionResult> GetEmployeeById(int id){
var employee = await _employeeRepository.GetEmployee(id);

if(employee == null){
return NotFound();
}

return employee;
}
[HttpGet("{id}")]
public Task<IActionResult> GetEmployeeById(int id){
var employee = await _employeeRepository.GetEmployee(id);

if(employee == null){
return NotFound();
}

return employee;
}
1 Reply
Accord
Accord16mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server