Example #1
0
        private static void ProcessJsonRequestError(ExceptionContext filterContext)
        {
            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
            if (filterContext.Exception is HttpException)
            {
                filterContext.HttpContext.Response.StatusCode =
                    (filterContext.Exception as HttpException).GetHttpCode();
                filterContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;
            }
            else
            {
                filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.OK;
            }

            filterContext.HttpContext.Response.StatusDescription = HttpWorkerRequest.GetStatusDescription(filterContext.HttpContext.Response.StatusCode);

            var jsonResponse = new ChalkableJsonResponce(ExceptionViewData.Create(filterContext.Exception))
            {
                Success = false
            };

            var jsonresult = new ChalkableJsonResult(false)
            {
                Data = jsonResponse,
                SerializationDepth = 4
            };

            filterContext.Result = jsonresult;
        }
Example #2
0
        protected void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

            // Get the exception object.
            Exception exc = Server.GetLastError();

            if (Context.Request.IsApiRequest() || Context.Request.IsAjaxRequest())
            {
                Context.ClearError();

                Context.Response.TrySkipIisCustomErrors = true;
                if (exc is HttpException)
                {
                    Context.Response.StatusCode = (exc as HttpException).GetHttpCode();
                    Context.Response.SuppressFormsAuthenticationRedirect = true;
                }
                else
                {
                    Context.Response.StatusCode = (int)HttpStatusCode.OK;
                }

                Context.Response.StatusDescription = HttpWorkerRequest.GetStatusDescription(Context.Response.StatusCode);

                var jsonResponse = new ChalkableJsonResponce(ExceptionViewData.Create(exc))
                {
                    Success = false
                };

                var serializer = new MagicJsonSerializer(true)
                {
                    MaxDepth = 4
                };
                var result = serializer.Serialize(jsonResponse);

                Context.Response.ContentType = "application/json";
                Context.Response.Write(result);

                return;
            }

            // Handle HTTP errors
            if (exc is HttpException)
            {
                // The Complete Error Handling Example generates
                // some errors using URLs with "NoCatch" in them;
                // ignore these here to simulate what would happen
                // if a global.asax handler were not implemented.
                if (exc.Message.Contains("NoCatch") || exc.Message.Contains("maxUrlLength"))
                {
                    // ReSharper disable once RedundantJumpStatement
                    return;
                }
            }

#if !DEBUG
            RaygunClient.SendInBackground(exc);
#endif
        }
        protected void PrepareJsonData(object data, string name, int maxDepth = 4)
        {
            var jsonResponse = new ChalkableJsonResponce(data);
            var serializer   = new MagicJsonSerializer(false)
            {
                MaxDepth = maxDepth
            };
            var res = serializer.Serialize(jsonResponse);

            ViewData[name] = res;
        }