I'm trying to set 404 HTTP response status from a block's function.
With this code works
but no way to to set the 404 status without exiting, i've found only solutions for controllers.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.Sign up to join this community
You shouldn't be modifying the response code with in a block, it should be in the controller. Your block should only contain logic that is used within template files to format data etc.
But in your controller to return a 404 you can use the following after injecting the resultForwardFactory
I've attached a few core Magento examples of it.