Last active
August 29, 2015 14:21
-
-
Save Mark-Broadhurst/2397b966daf2e7718c33 to your computer and use it in GitHub Desktop.
ASP.NET MVC Json Error Handler Attribute
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
namespace CII.Mercury.CRM | |
{ | |
#region Namespaces | |
using System.Net; | |
using System.Web.Mvc; | |
#endregion | |
public class JsonErrorHandlerAttribute : FilterAttribute, IExceptionFilter | |
{ | |
public void OnException(ExceptionContext filterContext) | |
{ | |
filterContext.HttpContext.Response.StatusCode = 500; | |
filterContext.ExceptionHandled = true; | |
filterContext.Result = new JsonResult | |
{ | |
Data = new | |
{ | |
success = false, | |
message = filterContext.Exception.Message, | |
#if DEBUG | |
type = filterContext.Exception.GetType().Name, | |
stacktrace = filterContext.Exception.StackTrace, | |
source = filterContext.Exception.Source | |
#endif | |
}, | |
JsonRequestBehavior = JsonRequestBehavior.AllowGet | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment