-1
Good morning,
I’m trying to return error message when something goes wrong in the api, I’ve done it for all the request of the api, but for one specific error, the action that shows all users that is IEnumerable
.
here is my code;
[HttpGet]
public IEnumerable<User> GetAll()
{
try
{
return userRepository.GetAll();
}
catch (Exception ex)
{
return StatusCode(500,ex.InnerException.Message);
}
}
How do I return the error? mine
return StatusCode(500,ex.InnerException.Message);
gives the following error
Cannot implicitly convert type 'Microsoft.AspNetCore.Mvc.ObjectResult' to 'System.Collections.Generic.IEnumerable<API.Models.User>'. An explicit conversion exists (are you missing a cast?) [API]