We’ve been happily using SXA OOTB Components [and still doing the same :)]. But suddenly one day we started getting errors on the Site. Where the page would give an error. After troubleshooting further we figured out that. The data source item was deleted and the component was still looking for that data source item.
If it had been a custom component or MVC Component. We would have handled that exception. But unfortunately, that’s not the case with OOTB SXA Components.
But we didn’t want to break a full page because of an error in one of the components. Instead, we wanted to keep the full page working without an error-ed component.
If it had been an MVC solution there are plenty of blogs to handle this using the Global MVC Rendering exception handling approach. But unfortunately, we couldn’t found any blog for SXA to do the same.
That’s why this blog post is coming to an existence on this earth!
Solution
We stumbled upon following posts to do the same in MVC (Thank you so much for this post):
Quick show config revealed that SXA has “SxaPageModeRenderingErrorStrategy” to handle such error in Experience editor mode. We noticed that the errored component was throwing and showing errors in Experience editor mode.
That was our Eureka Moment! We fired up the reflector and figured out the next steps.
Putting it together for you. So, you can go home (Or as per New Normal, go to the living room from the working room) on time to spend time with your loved ones!
We are handling our custom pipeline after SxaPageModeRenderingErrorStrategy which is logging exception as HTML comment on the page when the site is in normal mode and show error on page when the site is in experience editor mode (That part is done by OOTB handler). You can change it as per your need.
In case you want to disable this functionality in any environment. you can set SCBasics.IsCustomErrorEnabled to false