#20570: Log views execution exceptions

Work Item: 20570
This commit is contained in:
Sebastien Ros
2014-03-24 14:12:29 -07:00
parent 3fa9bce1ec
commit f219e4fb58
2 changed files with 31 additions and 8 deletions

View File

@@ -296,7 +296,8 @@ namespace Orchard.OutputCache.Filters {
_filter = null;
if (_previousFilter != null) {
response.Filter = _previousFilter;
}
}
return;
}
// ignore error results from cache

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web.Http.Description;
using System.Web.Mvc;
using Orchard.Logging;
using Orchard.Mvc;
@@ -9,7 +10,7 @@ using Orchard.Mvc.Filters;
using IFilterProvider = Orchard.Mvc.Filters.IFilterProvider;
namespace Orchard.Exceptions.Filters {
public class UnhandledExceptionFilter : FilterProvider, IActionFilter {
public class UnhandledExceptionFilter : FilterProvider, IActionFilter, IResultFilter {
private readonly IExceptionPolicy _exceptionPolicy;
private readonly IOrchardServices _orchardServices;
private readonly Lazy<IEnumerable<IFilterProvider>> _filterProviders;
@@ -30,15 +31,12 @@ namespace Orchard.Exceptions.Filters {
}
public void OnActionExecuted(ActionExecutedContext filterContext) {
// for exceptions which occured during the action execution
// don't provide custom errors if the action has some custom code to handle exceptions
if(!filterContext.ActionDescriptor.GetCustomAttributes(typeof(HandleErrorAttribute), false).Any()) {
if (!filterContext.ActionDescriptor.GetCustomAttributes(typeof(HandleErrorAttribute), false).Any()) {
if (!filterContext.ExceptionHandled && filterContext.Exception != null) {
if (_exceptionPolicy.HandleException(this, filterContext.Exception)) {
var shape = _orchardServices.New.ErrorPage();
shape.Message = filterContext.Exception.Message;
shape.Exception = filterContext.Exception;
filterContext.ExceptionHandled = true;
// inform exception filters of the exception that was suppressed
@@ -51,6 +49,10 @@ namespace Orchard.Exceptions.Filters {
filterContext.Result = exceptionContext.Result;
}
else {
var shape = _orchardServices.New.ErrorPage();
shape.Message = filterContext.Exception.Message;
shape.Exception = filterContext.Exception;
filterContext.Result = new ShapeResult(filterContext.Controller, shape);
filterContext.RequestContext.HttpContext.Response.StatusCode = 500;
@@ -73,15 +75,35 @@ namespace Orchard.Exceptions.Filters {
// Dont get the user stuck in a 'retry loop' by
// allowing the Referrer to be the same as the Request
model.ReferrerUrl = request.UrlReferrer != null &&
request.UrlReferrer.OriginalString != model.RequestedUrl ?
request.UrlReferrer.OriginalString != model.RequestedUrl ?
request.UrlReferrer.OriginalString : null;
filterContext.Result = new ShapeResult(filterContext.Controller, model);
filterContext.RequestContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
filterContext.ExceptionHandled = true;
// prevent IIS 7.0 classic mode from handling the 404/500 itself
filterContext.RequestContext.HttpContext.Response.TrySkipIisCustomErrors = true;
}
}
public void OnResultExecuting(ResultExecutingContext filterContext) {
}
public void OnResultExecuted(ResultExecutedContext filterContext) {
// for exceptions which occured during the action execution
// don't provide custom errors if the action has some custom code to handle exceptions
if (!filterContext.ExceptionHandled && filterContext.Exception != null) {
if (_exceptionPolicy.HandleException(this, filterContext.Exception)) {
// inform exception filters of the exception that was suppressed
var exceptionContext = new ExceptionContext(filterContext.Controller.ControllerContext, filterContext.Exception);
foreach (var exceptionFilter in _filterProviders.Value.OfType<IExceptionFilter>()) {
exceptionFilter.OnException(exceptionContext);
}
}
}
}
}
}