Skip to content

Instantly share code, notes, and snippets.

@spudstuff
Created March 27, 2013 21:02
Show Gist options
  • Save spudstuff/5257974 to your computer and use it in GitHub Desktop.
Save spudstuff/5257974 to your computer and use it in GitHub Desktop.
using System;
using umbraco;
using Umbraco.Core;
using Umbraco.Core.Events;
using umbraco.interfaces;
namespace MyNameSpace
{
public class StartupEventHandlers : IApplicationStartupHandler
{
public StartupEventHandlers()
{
umbraco.macro.Error += macro_Error;
}
void macro_Error(object sender, Umbraco.Core.Events.MacroErrorEventArgs e)
{
// Banner ads - who cares?
if(e.Alias == "bannerAds")
{
// Hide the macro
e.Behaviour = MacroErrorBehaviour.Silent;
// But still log the issue (your own logging code)
log.ErrorException(String.Format("Macro failed to load: {0}", e.Alias), e.Exception);
}
// Search is real important so we want to blow up the site if it's not working so our custom error page is shown
if(e.Alias == "siteSearch")
{
// Force exception to be thrown
e.Behaviour = MacroErrorBehaviour.Throw;
// And log the issue (your own logging code)
log.ErrorException(String.Format("Macro failed to load: {0}", e.Alias), e.Exception);
}
// All other cases will use the behaviour defined in umbracoSettings for <MacroErrors>
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment