0

Our requirement is to show site specific error page if the requested page is not found.

We have handled item not found using HttpRequestBegin pipeline Item resolver. If the context item is null we are setting the context item as page not found item.

But in headless mode always getting context item as sitecore hence not able to set the page not found item to context item.

Please let me know how to implement the 404 errors in headless mode.

Thanks

  • Why don't you use the out of the box "page not found" process? why have you implemented your own HttpRequestBegin pipeline? – Artsem Prashkovich Sep 1 at 7:54
  • We have to display the site specific error page hence we have implemented – Nirupama Reddy Sep 1 at 12:50
1

There are two types of Item resolver in JSS:

First and which you already implemented:

public class ResolveItem : HttpRequestProcessor
    {
        public override void Process(HttpRequestArgs args)
        {
            var item = ANY YOUR LOGIC TO GET 404 item.
            Context.Item = item;
        }
    }

<configuration
    xmlns:patch="http://www.sitecore.net/xmlconfig/"
    xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <pipelines>
      <httpRequestBegin>
        <processor type="{your-namespace}.ResolveItem, {your-assembly-name}"
                   patch:after="*[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']">
        </processor>
      </httpRequestBegin>
    </pipelines>
  </sitecore>
</configuration>

And Second one Item resolver is for Layout Service:

public class LayoutServiceItemResolver
    {
            
        public void Process(RequestBeginArgs args)
        {
                var item = ANY YOUR LOGIC TO GET 404 item.
                Context.Item = item;           
        }
    }



<configuration
    xmlns:patch="http://www.sitecore.net/xmlconfig/"
    xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <pipelines>
      <mvc.requestBegin>
        <processor type="{your-namespace}.LayoutServiceItemResolver, {your-assembly-name}" resolve="true">
        </processor>
      </mvc.requestBegin>
    </pipelines>
  </sitecore>
</configuration>

Both of them are required. First one is used when you request the page by URL, second one - when you navigate on you browser (which means utilizes a jss routing)

| improve this answer | |
  • Thanks for the detail explanation. with first approach it’s working fine in integrated mode. The issue is with the headless implementation. Do we need to change anything for the headless implementation? – Nirupama Reddy Sep 1 at 17:24
  • Have you implemented LayoutServiceItemResolver as on example above? please note, that it is another pipeline as you have. This is used to resolve item exactly for headless. – Artsem Prashkovich Sep 1 at 17:31
  • Not yet implemented, will try this and IContentSearcher, IUrlService are in which assembly i am not able to get these. – Nirupama Reddy Sep 2 at 12:48
  • @NirupamaReddy am sorry, I forgot to remove it from example. You actually don't need this constructor. I have updated the answer – Artsem Prashkovich Sep 2 at 12:49
  • Thanks for the update @Artsem Prashkovich. I have tried this and here as well the context item by default coming as sitecore, end up with same issue – Nirupama Reddy Sep 2 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.