*/ abstract class AbstractExceptionHandlingController extends ActionController { /** * Message to show when an element is not found (404) * @var string */ protected $notFoundMessage = 'Element not found'; /** * Message to show when an unknown error occurs (e.g. API exception) * @var string */ protected $genericErrorMessage = 'Es ist ein schwerer Fehler aufgetreten.'; /** * We currently do not need this. * * Handles a request. * The result output is returned by altering the given response. * * @param object $request The request object * @param object $response The response, modified by this handler * * @return void */ public function DEACTprocessRequest( \TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response ) { try { parent::processRequest($request, $response); } catch (PageNotFoundException $e) { $this->handleNotFoundError($e); } catch (\Exception $e) { $this->handleGenericError($e); } } /** * Call the correct action method * * @return void */ public function callActionMethod() { try { parent::callActionMethod(); } catch (PageNotFoundException $e) { $this->handleNotFoundError($e); } catch (\Exception $e) { $this->handleGenericError($e); } } /** * Handle a "element not found"-exception * * @param object $exception Exception * * @return void */ public function handleNotFoundError(\Exception $e) { //$GLOBALS['TSFE']->pageNotFoundAndExit($this->notFoundMessage); $this->renderError( 'typo3conf/ext/extname/Resources/Private/Templates/Error/NotFound.html', $this->notFoundMessage, $e ); $this->response->setStatus(404); } /** * Handle a generic undetermined error * * @param object $exception Exception * * @return void */ public function handleGenericError(\Exception $e) { /* $GLOBALS['TSFE']->pageUnavailableAndExit( $this->genericErrorMessage, 'HTTP/1.1 500 Internal Server Error' ); /**/ $this->renderError( 'typo3conf/ext/extname/Resources/Private/Templates/Error/Generic.html', $this->genericErrorMessage, $e ); $this->response->setStatus(500); } /** * Render an error message into a template * * @param string $templateFile Template path * @param string $message Error message * @param object $e Exception that caused this error message * * @return void */ protected function renderError($templateFile, $message, \Exception $e) { $this->view->setTemplatePathAndFilename($templateFile); $this->view->assign('error', $message); $this->view->assign('exception', $e); $this->response->setContent($this->view->render()); } } ?>