Reputation: 6158
I have a extension and when I call this extension with an ID of a record that not or no longer exists I get an Exception Object of type My\Model\... with identity "1035" not found.
The page itself got the header status 500.
What I would like to do in this case is to show my default 404 page. Is this possible? And how can I do that?
Upvotes: 0
Views: 1858
Reputation: 7939
I guess you are using a method like
public function detailAction(\YourVendor\Ext\Domain\Model\MyModel $model)
In that case, it is not that easy because the exception is already thrown in extbase's core. You can take a look how I solve it for my news extension:
/**
* @param RequestInterface $request
* @param ResponseInterface $response
* @throws \Exception
*/
public function processRequest(RequestInterface $request, ResponseInterface $response)
{
try {
parent::processRequest($request, $response);
} catch (\Exception $exception) {
$this->handleKnownExceptionsElseThrowAgain($exception);
}
}
/**
* @param \Exception $exception
* @throws \Exception
*/
private function handleKnownExceptionsElseThrowAgain(\Exception $exception)
{
$previousException = $exception->getPrevious();
if (
$this->actionMethodName === 'detailAction'
&& $previousException instanceof \TYPO3\CMS\Extbase\Property\Exception
&& isset($this->settings['detail']['errorHandling'])
) {
$this->handleNoNewsFoundError($this->settings['detail']['errorHandling']);
} else {
throw $exception;
}
}
In the method handleNoNewsFoundError
you can do then anything you want to, e.g. calling $GLOBALS['TSFE']->pageNotFoundAndExit('No news entry found.');
.
Upvotes: 1
Reputation: 334
Untested, but from a logical POV you should just catch the exception and then let your controller decide what to do (in your case: show a 404 page).
Upvotes: 0