blipson89 / Synthesis

Synthesis is a universal object mapper for Sitecore
MIT License
75 stars 25 forks source link

Add flexibility with ResilientExecuteRenderer to allow customized exception behavior #105

Closed sitecorepm closed 2 years ago

sitecorepm commented 2 years ago

Do you want to request a feature or report a bug? FEATURE

What is the current behavior? Any exception caught by ResilientExecuteRenderer logs the exception with Log.Error(...)

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected/desired behavior? Move the Log.Error statement into its own new virtual method (LogException?) to allow it to be easily overridden.

public override void Process(RenderRenderingArgs args)
{
    try
    {
        base.Process(args);
    }
    catch (Exception exception)
    {
        args.Cacheable = false;
        LogException(exception);
        Exception ex = ProcessException(exception);
        RenderingErrorModel model = CreateRenderingErrorModel(args, ex);
        if (!DispatchPossibleModelException(model, args.PageContext.RequestContext, args.Writer))
        {
            DispatchException(model, args.PageContext.RequestContext, args.Writer);
        }
    }
}

protected virtual void LogException(Exception exception)
{
    Log.Error("Error occurred rendering a view.", exception, GetType());
}

I can submit a PR if this seems reasonable.

Please mention your Sitecore version and Synthesis version. Sitecore 9.3 Synthesis 9.1.0.2

blipson89 commented 2 years ago

@sitecorepm it's a reasonable request. If you put in a PR, I'll approve it.

Thanks!

blipson89 commented 2 years ago

Added to 9.1.6