Example #1
0
        public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext == null || !filterContext.HttpContext.IsCustomErrorEnabled)
            {
                base.OnException(filterContext);

                return;
            }

            if (filterContext.ExceptionHandled)
            {
                return;
            }

            if (filterContext.Exception != null)
            {
                _log.Error(filterContext.Exception, "Unhandled exception");
            }
            else
            {
                _log.Warn("Unhandled exception. Target exception was not found in the ExceptionContext.");
            }

            WebErrorHandler.Handle(HttpContext.Current, filterContext.Exception);

            filterContext.ExceptionHandled = true;
            filterContext.Result           = null;
        }
        public override void Handle(ExceptionHandlerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (!HttpContext.Current.IsCustomErrorEnabled)
            {
                _log.Error(context.Exception, "Application error.");

                base.Handle(context);

                return;
            }

            if (context.Exception != null)
            {
                _log.Error(context.Exception, "Unhandled api exception.");
            }
            else
            {
                _log.Warn("Unhandled api exception. Target exception was not found in the ExceptionHandlerContext.");
            }

            WebErrorHandler.Handle(HttpContext.Current, context.Exception);

            context.Result = null;
        }