Esempio n. 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;
        }
Esempio n. 2
0
        private ActionResult HandlReportProcessingException(LocalProcessingException exception)
        {
            //TODO: remove this later
            Response.TrySkipIisCustomErrors = true;
            Response.StatusCode             = 500;
            Response.StatusDescription      = HttpWorkerRequest.GetStatusDescription(Response.StatusCode);

            var errorMessages = new List <string>()
            {
                exception.Message
            };
            var ex = exception.InnerException;

            while (ex != null)
            {
                errorMessages.Add(ex.Message);
                ex = ex.InnerException;
            }

            return(new ChalkableJsonResult(false)
            {
                Data = new ChalkableJsonResponce(new
                {
                    Exception = ExceptionViewData.Create(exception),
                    InnerException = ExceptionViewData.Create(exception.InnerException),
                    Messages = errorMessages
                })
                {
                    Success = false
                },
                ContentType = HTML_CONTENT_TYPE,
                SerializationDepth = 4
            });
        }
Esempio n. 3
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
        }
Esempio n. 4
0
 private JsonResult ChlkExceptionJsonResult(Exception ex)
 {
     return new JsonResult
     {
         Data = new
         {
             success = false,
             data = ExceptionViewData.Create(ex, ex.InnerException)
         },
         JsonRequestBehavior = JsonRequestBehavior.AllowGet
     };
 }
Esempio n. 5
0
        public ChalkableJsonResponce(object data)
        {
            Data    = data;
            Success = true;

            var exception = data as ChalkableException;

            if (exception != null)
            {
                Data    = ExceptionViewData.Create(exception);
                Success = false;
            }
        }
Esempio n. 6
0
 protected ActionResult HandleAttachmentException(Exception exception)
 {
     Response.TrySkipIisCustomErrors = true;
     Response.StatusCode             = 500;
     Response.StatusDescription      = HttpWorkerRequest.GetStatusDescription(Response.StatusCode);
     return(new ChalkableJsonResult(false)
     {
         Data = new ChalkableJsonResponce(ExceptionViewData.Create(exception))
         {
             Success = false
         },
         ContentType = HTML_CONTENT_TYPE,
         SerializationDepth = 4
     });
 }