A simple way to handle an exception on any particular method is:
using Microsoft.AspNetCore.Http;...public ActionResult MyAPIMethod(){ try { var myObject = ... something; return Json(myObject); } catch (Exception ex) { Log.Error($"Error: {ex.Message}"); return StatusCode(StatusCodes.Status500InternalServerError); } }