Skip to content

Instantly share code, notes, and snippets.

@ZackStone
Created February 20, 2018 17:38
Show Gist options
  • Save ZackStone/a60fac99dd2f457ed46569342b2c9e4a to your computer and use it in GitHub Desktop.
Save ZackStone/a60fac99dd2f457ed46569342b2c9e4a to your computer and use it in GitHub Desktop.
protected void Application_Error(object sender, EventArgs e)
{
// Get the exception object.
Exception ex = Server.GetLastError();
// Log the exception and notify system operators
Logger.GravarLogErro(ex);
// Em modo debug, deixa estourar a exceção na tela
CompilationSection compilationSection = (CompilationSection)ConfigurationManager.GetSection(@"system.web/compilation");
if (!compilationSection.Debug)
{
// Clear the error from the server
Server.ClearError();
bool isAjaxCall = string.Equals("XMLHttpRequest", Context.Request.Headers["x-requested-with"], StringComparison.OrdinalIgnoreCase);
if (isAjaxCall)
{
Context.Response.ContentType = "application/json";
Context.Response.StatusCode = 500;
}
else
{
// Code that runs when an unhandled error occurs
Server.TransferRequest("~/Erro");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment