public override void OnException(HttpActionExecutedContext actionContext)
        {
            actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.InternalServerError);
            var resex = new HttpResponseMessage(HttpStatusCode.InternalServerError);
            var res   = new ErrResponsePoco();

            var req = new RequestDTO(actionContext.Request);

            var task = Task.Run(async() => {
                res.DbErrorId = await Logging.WriteDebugInfoToErrorLog("WebAPI Error", actionContext.Exception, req);
            });

            task.Wait();
            res.ErrorMessage = actionContext.Exception.Message;
            res.ErrorTitle   = "API Error";

            if (HttpContext.Current != null)
            {
                HttpContext.Current.Items.Add("ErrorID", res.DbErrorId);
                HttpContext.Current.ClearError();
            }

            resex.Content = new ObjectContent(typeof(ErrResponsePoco), res, new JsonMediaTypeFormatter());

            throw new HttpResponseException(resex);
        }
        public override void OnException(ExceptionContext filterContext)
        {
            var message = string.Format("Exception     : {0}\n" +
                                        "InnerException: {1}",
                                        filterContext.Exception,
                                        filterContext.Exception.InnerException);

            var request = new RequestDTO(filterContext.RequestContext.HttpContext);

            string eid  = null;
            var    task = Task.Run(async() => {
                eid = await Logging.WriteDebugInfoToErrorLog(message, filterContext.Exception, request, null);
            });

            task.Wait();

            filterContext.HttpContext.Items.Add("ErrorID", eid);
            if (HttpContext.Current.Session != null)
            {
                HttpContext.Current.Session["ErrorID"] = eid;
            }

            filterContext.ExceptionHandled = true;

            base.OnException(filterContext);

            // Verify if AJAX request
            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                // Use partial view in case of AJAX request
                var result = new JsonResult
                {
                    Data = new ErrResponsePoco
                    {
                        DbErrorId = eid
                    }
                };
                filterContext.Result = result;
            }
            else
            {
                filterContext.Result = new ViewResult
                {
                    ViewName = "~/Views/Shared/Error.cshtml"
                };
            }
        }
Exemplo n.º 3
0
 public ErrorMgrDb(RequestDTO request)
 {
     _request = request;
     _repo    = new ErrorItemsRepo();
 }
 public ErrorMgr(RequestDTO request)
 {
     _mgr = (IErrorMgr) new ErrorMgrDb(request);
 }