Ejemplo n.º 1
0
 public FoundationException(string message, FoundationException inner) : base(message, inner)
 {
 }
        public virtual void OnException(ExceptionContext filterContext)
        {
            string errorCode = string.Empty;

            if (filterContext == null)
            {
                throw new ArgumentNullException(nameof(filterContext));
            }

            if (filterContext.IsChildAction || (filterContext.ExceptionHandled))
            {
                return;
            }
            var exception = filterContext.Exception;

            if ((new HttpException(null, exception).GetHttpCode() != 500) ||
                !ExceptionType.IsInstanceOfType(exception))
            {
                return;
            }
            // Check if the exception type is custom CTPException
            var foundationException = exception as FoundationException;

            if (foundationException != null)
            {
                var rapidException = new FoundationException(_rapidExceptionType, _rapidExceptionCategory, (System.Exception)exception);
                errorCode = rapidException.ExceptionCode;
                switch (rapidException.ExceptionCategory)
                {
                case ExceptionCategories.WARNING:
                    LogManager.Warning(rapidException.ExceptionCode);
                    break;

                case ExceptionCategories.ERROR:
                    LogManager.Exception(rapidException);
                    break;

                case ExceptionCategories.FATAL:
                    LogManager.Fatal(rapidException);
                    break;

                default:
                    LogManager.Exception(rapidException);
                    break;
                }
            }
            else
            {
                // Log exception
                LogManager.Exception(exception);
            }
            var errorFilePath = RedirectCustomErrorsView();

            if (!string.IsNullOrEmpty(errorFilePath))
            {
                // Show error view
                ErrorFilterHelper.SetFilerContext(filterContext, Master, View);
                if (System.Web.HttpContext.Current != null)
                {
                    System.Web.HttpContext.Current.Response.RedirectPermanent(String.Format("/Error404", errorCode), true);
                }
            }
            else
            {
                throw exception;
            }
        }