From 8ea1af56ab58312c21fa7e54261b99f16543e96f Mon Sep 17 00:00:00 2001 From: John Kilmister Date: Tue, 11 Jul 2017 16:22:21 +0100 Subject: [PATCH] U4-10143 - Improved error messages when we retrieve current xml node --- src/Umbraco.Web/umbraco.presentation/library.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs index 38b8b1b95d..4ab89c5c7d 100644 --- a/src/Umbraco.Web/umbraco.presentation/library.cs +++ b/src/Umbraco.Web/umbraco.presentation/library.cs @@ -1393,15 +1393,25 @@ namespace umbraco /// An XpathNodeIterator containing the current page as Xml. public static XPathNodeIterator GetXmlNodeCurrent() { + var pageId = ""; + try { var nav = Umbraco.Web.UmbracoContext.Current.ContentCache.GetXPathNavigator(); - nav.MoveToId(HttpContext.Current.Items["pageID"].ToString()); + var pageIdItem = HttpContext.Current.Items["pageID"]; + + if (pageIdItem == null) + { + throw new NullReferenceException("pageID not found in the current HTTP context"); + } + + pageId = pageIdItem.ToString(); + nav.MoveToId(pageId); return nav.Select("."); } catch (Exception ex) { - LogHelper.Error("Could not retrieve current xml node", ex); + LogHelper.Error(string.Concat("Could not retrieve current xml node for page Id ",pageId), ex); } XmlDocument xd = new XmlDocument();