Sometimes your Extbase-extension crashes and throws an exception, especially when it tries to fetch entities which were hidden or deleted . As for development this might be acceptable, for live-environment it is not. But hey, a solution to this problem is near: Catch the exception and pass it into the regular TYPO3-error-handling (which is normally a 404).
You just need to overwrite the function processRequest in your Controller:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/** * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request * @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response * @throws \Exception|\TYPO3\CMS\Extbase\Property\Exception */ public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response) { try { parent::processRequest($request, $response); } catch(\TYPO3\CMS\Extbase\Property\Exception $e) { if ($e->getPrevious() instanceof \TYPO3\CMS\Extbase\Property\Exception\TargetNotFoundException) { $GLOBALS['TSFE']->pageNotFoundAndExit('Entity not found.'); } else { throw $e; } } } |
Thanks to following articles (only in german):
http://nerdcenter.de/extbase-fehlerbehandlung/
http://blog.mindscreen.de/2013/404-handling-statt-exception-in-extbase-catching-1297759968/