In TYPO3 v10 you can't use the $TSFE->pageNotFoundAndExit() anymore. But the $this->request in the controller action gives an exception when using the ErrorController PageNotFound method.
In TYPO3 v10 you can't use the $TSFE->pageNotFoundAndExit() anymore. But the $this->request in the controller action gives an exception when using the ErrorController PageNotFound method.
$TSFE->pageNotFoundAndExit() will be removed in TYPO3 v10.0. Use TYPO3's ErrorController with Request/Response objects instead.
In your controller you have to use the $GLOBALS['TYPO3_REQUEST'] instead of $this->request.
Tip: by using the ImmediateResponseException further action won't be invoked.
Example method:
$response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$GLOBALS['TYPO3_REQUEST'],
'your 404 message'
);
throw new ImmediateResponseException($response, 1591428020);