How can I create a custom error pages in my Magento 2 site. For example this pages: 500, 401, 403, and 404
.
I tried for create block:
$layout = $this->_view->getLayout();
$block = $layout->createBlock('Training\Test\Block\Test');
$this->getResponse()->appendBody($block->toHtml());
But not working return error
Catalog Layer has been already created
Below is my Controller
class View{
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Catalog\Block\Product\ProductList\Toolbar $toolbar,
PageFactory $resultPageFactory,
\Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory,
\Magento\Framework\UrlInterface $url
) {
$this->toolbar = $toolbar;
$this->resultPageFactory = $resultPageFactory;
$this->resultForwardFactory = $resultForwardFactory;
$this->url = $url;
}
public function beforeExecute(\Magento\Catalog\Controller\Category\View $category)
{
$product_limit = $category->getRequest()->getParam('product_list_limit');
$available_limits = $this->toolbar->getAvailableLimit();
if(!in_array($product_limit, $available_limits) && !empty($product_limit))
{
/*$norouteUrl = $this->url->getUrl('noroute');
$category->getResponse()->setRedirect($norouteUrl);
return;*/
return $this->resultForwardFactory->create()->forward('noroute');
}
}
}
In that I want to replace return $this->resultForwardFactory->create()->forward('noroute');
with my custom error page URL