Last active
November 23, 2023 16:57
-
-
Save steliodibello/839faed9f90c220d739d2cad9b2fcbb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace XXXX.Controllers | |
{ | |
using Microsoft.AspNetCore.Mvc; | |
using Sitecore.AspNet.RenderingEngine; | |
using Sitecore.LayoutService.Client.Exceptions; | |
public class SitecoreController : Controller | |
{ | |
public IActionResult Index() | |
{ | |
var request = HttpContext.GetSitecoreRenderingContext(); | |
if (request == null || request.Response == null) | |
{ | |
return new EmptyResult(); | |
} | |
//Check if layout service call return any error | |
if (request.Response.HasErrors) | |
{ | |
//loop through errors | |
foreach (var error in request.Response.Errors) | |
{ | |
switch (error) | |
{ | |
//this is the case of 404 errors | |
case ItemNotFoundSitecoreLayoutServiceClientException _: | |
Response.Redirect("/404"); | |
break; | |
} | |
} | |
} | |
return View(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment