Quantcast
Channel: ASP.NET Core Web API exception handling - Stack Overflow
Viewing all articles
Browse latest Browse all 13

Answer by Chris Halcrow for ASP.NET Core Web API exception handling

$
0
0

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);    }         }

Viewing all articles
Browse latest Browse all 13

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>