0

We have a Sitecore site that's using Glass.Mapper. We also have a simple two step workflow, "Draft > Ready for publish" on all items. There are global items, which are promos that can be placed on pages. Authors create promos, then create pages and place the promos on the pages.

If a page is published but a promo hasn't been published, the page returns this error: Constructor on type 'OurSite.Sitecore.Models.IPromo' not found.

Since the scenario of authors failing to publish new promos is a real one, I would like to prevent this error from happening, so that the page just renders without the promo. Thoughts?

alkar
  • 5,459
  • 7
  • 27
  • 43
Scott
  • 1,011
  • 1
  • 15
  • 30

2 Answers2

1

Another option would be to validate the datasource of components in the getRenderer pipeline. Marek has blogged about this with a solid solution:

http://www.skillcore.net/sitecore/sitecore-automated-validation-of-mvc-rendering-datasource

This also handles the scenario where components without datasource (ie. item was deleted) break the page in PageEditor.

That being said I also believe that in addition you should have a proper exception strategy as well. The link Jim Noellsch posted is a good one. I recall this one from Charlie Turano to be a solid one as well:

http://www.hhogdev.com/blog/2015/june/mvc-rendering-exception-handler.aspx

RvanDalen
  • 1,155
  • 5
  • 10
  • We ended up implementing the Jim Noellsch MVC rendering exception handling. Very clean solution. – Scott Nov 30 '15 at 22:54
0

Assuming IPromo is an interface, convert it to a class model Promo. If this is an MVC solution, you could also override the OnException method to quietly suppress missing content.

Jim Noellsch
  • 714
  • 4
  • 7
  • Any thoughts on where I put the OnException code in a Sitecore MVC solution to suppress a rendering (MVC view) that errors? – Scott Sep 16 '15 at 23:32
  • If they aren't controller renderings, you might have to tap into the `mvc.getRendering` pipeline as described by John West [here](http://www.sitecore.net/Learn/Blogs/Technical-Blogs/John-West-Sitecore-Blog/Posts/2012/09/Handling-Rendering-Exceptions-in-MVC-Solutions-with-the-Sitecore-ASPNET-CMS.aspx) – Jim Noellsch Sep 17 '15 at 02:06