Last active
April 4, 2017 01:34
-
-
Save scottsauber/5a35de6d7fe0bee5954d47b0206051f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.AspNetCore.Diagnostics; | |
using Microsoft.AspNetCore.Mvc; | |
namespace GlobalExceptionHandling.Controllers | |
{ | |
public class HomeController : Controller | |
{ | |
public IActionResult Error() | |
{ | |
// Get the details of the exception that occurred | |
var exceptionFeature = HttpContext.Features.Get<IExceptionHandlerPathFeature>(); | |
if (exceptionFeature != null) | |
{ | |
// Get which route the exception occurred at | |
string routeWhereExceptionOccurred = exceptionFeature.Path; | |
// Get the exception that occurred | |
Exception exceptionThatOccurred = exceptionFeature.Error; | |
// TODO: Do something with the exception | |
// Log it with Serilog? | |
// Send an e-mail, text, fax, or carrier pidgeon? Maybe all of the above? | |
// Whatever you do, be careful to catch any exceptions, otherwise you'll end up with a blank page and throwing a 500 | |
} | |
return View(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment