This logic should probably be a listener to the [`MvcEvent::DISPATCH_ERROR`](https://github.com/zendframework/zf2/blob/4fe2829353077239aafc9ffe39a15c07bba5b660/library/Zend/Mvc/MvcEvent.php#L25) event instead