On my current project, we return Task<IActionResult> in the controller actions. It makes it fairly painless to write useful unit tests.
Middleware Pipeline – a common location for returning errors, like via SetForbiddenResponse()
Because I was having issues locating these in MSDN (not there, look in https://docs.microsoft.com/en-us/aspnet/core/api instead), here’s a list of valid types that implement IActionResult in AspNetCore (dotnet core):
- ObjectResult (general handler)
This example returns a useful error to the consumer for debugging. JSON might be better in your case. There are properties on the object to tweak the response type.