Don't know and can't try now if it's change something, but I'm using eventsManager::attach with dispatch:beforeException
$eventsManager->attach(
'dispatch:beforeException',
new NotFoundPlugin()
);
And my NotFoundPlugin
public function beforeException(Event $event, MvcDispatcher $dispatcher, \Exception $exception)
{
error_log($exception->getMessage() . PHP_EOL . $exception->getTraceAsString());
if ($exception instanceof MvcDispatcherException) {
switch ($exception->getCode()) {
case DispatcherException::EXCEPTION_HANDLER_NOT_FOUND:
case DispatcherException::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(
[
'controller' => 'errors',
'action' => 'show404',
]
);
return false;
}
}
$dispatcher->forward(
[
'controller' => 'errors',
'action' => 'show500',
]
);
return false;
}