title: asp.net core app.UseExceptionHandler() to handle exceptions for certain endpoints?
body: <p>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 <code>[ApiController]</code> and calling clients will expect the return output to be JSON instead of regular HTML.</p>
  <p>In another project, I implement a custom exception handler using <code>app.UseExceptionHandler(...)</code> 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 <code>[ApiController]</code> controller; otherwise I still want to use <code>app.UseExceptionHandler(&quot;/Home/Error&quot;);</code>, as the exception came from a regular page and the response should be HTML.</p>
  <p>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?</p>