I'm adding some web API methods to an existing ASP.NET Core web app. This means my new web API controller(s) will have the attribute [ApiController] and calling clients will expect the return output to be JSON instead of regular HTML.
In another project, I implement a custom exception handler using app.UseExceptionHandler(...) which encodes the response in JSON, giving information about the exception. In this one, I want to do that, but only when the exception came from an action method inside an [ApiController] controller; otherwise I still want to use app.UseExceptionHandler("/Home/Error");, as the exception came from a regular page and the response should be HTML.
Is there a way I can set up an exception handler so that it knows where the exception came from, and render the response accordingly?
