I'm creating a login portal and if a user is not logged in but tries to access a page that they should be logged in for the system should show a 404 page.
I read that you can internally redirect requests using the $this->dispatcher->forward() method, however it doesn't render the 404 page, but simply continues executing the indexAction() method and the any response in the Index::notFound method is never shown, am I doing something wrong?
(I read the documentation on the dispatcher here)
My code:
class LoginController extends ControllerBase {
    public function initialize() {
        parent::initialize();
        if ($this->session->get('logged-in') == null) {
            $this->dispatcher->forward([
                "controller" => "Index", 
                "action" => "notFound"
            ]);
        }
    }
    public function indexAction() {
        exit("You are logged in")
    }
}