Manually throw 404 from Controller

This should work:

return function ($page) {
    
    if ('your condition') {
        echo page('error')->render();
        exit();
    } else {
       
        return [
           //...
        ];
    }

};